MySQL查询文章列表标签问题

WBOY
Release: 2016-06-06 20:23:08
Original
1306 people have browsed it

想问下像segmentfault,wordpress这样,文章列表,每条记录有标签,可以有多个。我不知道seg数据表是怎么设计的。说下WordPress的
文章表,
标签表:id,name,slug

文章与标签关系表:pid,tid

想问下这是怎么查询出来的?不要说循环。

能用SQL一次性查询出来吗?

回复内容:

想问下像segmentfault,wordpress这样,文章列表,每条记录有标签,可以有多个。我不知道seg数据表是怎么设计的。说下WordPress的
文章表,
标签表:id,name,slug

文章与标签关系表:pid,tid

想问下这是怎么查询出来的?不要说循环。

能用SQL一次性查询出来吗?

select id as pid from article where id in (select pid from tags_article where tid in (select tid from tags where name in (“标签”)))
很没效率

可以用全文索引,sphinx可以去研究下。反正搜索也是要用这个的。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!