Mysql 查找包含多个标签的文章?

2015 年 1 月 21 日
 alayii

文章包含多个标签,用关联表外理,表 articles, re_articles_tags, tags

如何能查找即有 A 标签又有 B 标签的文章?

4390 次点击
所在节点    问与答
4 条回复
cevincheung
2015 年 1 月 21 日
select * from articles where article_id in (select distinct(article_id) from tags where tags in ('tag1','tag2','tag3')) limit n
caixiexin
2015 年 1 月 21 日
select distinct a.* from articles a, re_articles_tags b where a.文章id=b.文章id and b.tag in (A ,B)
?
feiyuanqiu
2015 年 1 月 21 日
一个能用但是不太好的 SQL:

SELECT
DISTINCT a.*
FROM
re_articles_tags r1
JOIN re_articles_tags r2
ON r1.`article_id` = r2.`article_id`
AND r1.`tag_id` = 1
AND r2.`tag_id` = 2
JOIN articles a
ON r1.`article_id` = a.`article_id`
pi1ot
2015 年 1 月 21 日
这应该是适合lucene做的事情

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/164098

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX