文章包含多个标签,用关联表外理,表 articles, re_articles_tags, tags
如何能查找即有 A 标签又有 B 标签的文章?
1
cevincheung 2015-01-21 12:33:35 +08:00 1
select * from articles where article_id in (select distinct(article_id) from tags where tags in ('tag1','tag2','tag3')) limit n
|
2
caixiexin 2015-01-21 12:35:05 +08:00 1
select distinct a.* from articles a, re_articles_tags b where a.文章id=b.文章id and b.tag in (A ,B)
? |
3
feiyuanqiu 2015-01-21 14:26:28 +08:00
一个能用但是不太好的 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` |
4
pi1ot 2015-01-21 15:00:23 +08:00
这应该是适合lucene做的事情
|