【发布时间】:2014-07-15 10:14:18
【问题描述】:
我有 3 张桌子
**Posts**
id post_title
1 First_Post
2 Second_Post
3 Third_Post
**Tags**
id tag_name
1 Published
2 Favorites
3 Deleted
**PostTagRelatives**
id post_id tag_id
1 1 1
2 1 2
3 2 3
我使用查询
SELECT p.*, GROUP_CONCAT(PostTagRel.tag_id) AS tags FROM Posts p left
join PostTagRelatives PostTagRel on PostTagRel.post_id = p.id GROUP BY
p.id
而且效果很好。
我需要添加到 sql 查询以仅获取包含“已发布”和“收藏夹”标签的帖子。我尝试在 GROUP BY 之前插入一些条件,例如
WHERE (',' || tags || ',') LIKE '%,1,2,%'
但它没有帮助。
【问题讨论】: