标签
tag_id post_id value ------------------------ 1 1 some 2 1 good 3 1 title 4 2 some 5 2 good 6 3 some 7 4 good 8 4 title
帖子
post_id title ------------------- 1 some good title 2 some good 3 some 4 good title
我们如何能够得到一个包含价值POST_ID = 1和2 some ,并good在同一POST_ID?
some
good
所以结果是
RESULT title ---------- some good title some good
good title剂量显示some,因为标签的post_id = 4中没有值。 some不显示要求good
good title
尝试LIKE多次:
LIKE
SELECT * FROM post WHERE title LIKE '%some%' AND title LIKE '%good%'
您也可以像这样连接两个表:
SELECT post.post_id, title FROM Post RIGHT JOIN Tags ON post.post_id = tags.post_id WHERE Tags.value IN ('some','good') GROUP BY post.Post_ID HAVING COUNT(*)>1;