我有一个表posts
和一个表post_tags
这是我的帖子表结构示例:
post_id int(11)
post_user int(11)
post_title text
post_content longtext
这是我的 post_tags 结构示例:
post_id int(11)
tag_id int(11)
我需要的是从posts
表中选择同时具有tag_id
1 和 2 的所有帖子,我尝试了不同的连接但没有成功。
post_tags 表数据示例:
post_id tag_id
1 1
2 1
5 2
6 1
6 2
例如,在这里我的查询应该返回 post(来自 post 表),其 id 为 6,在示例 post_id 为 6 时,请注意 tag_id 1 和 tag_id 2 不仅有一个,而且同时有两个。