我有3个表(场景,类别,scenes_categories)在多对多的关系。MYSQL多个选择相同的类别?
场景(ID,标题,描述) 类别(ID,标题) scenes_categories(scene_id,CATEGORY_ID)
我有问题,查询数据以选择必须多个类别相匹配的场景。例如,我可能想要选择与类别3和类别5以及类别8匹配的场景,但我无法弄清楚如何使其发挥作用。
到目前为止,我已经得到的东西像
SELECT scenes.id, scenes.title, scenes.description
FROM scenes
LEFT JOIN scenes_categories ON scenes.id = scenes_categories.scene_id
LEFT JOIN categories ON scenes_categories.category_id = categories.id
WHERE scenes_categories.category_id = '3'
AND scenes_categories.category_id = '5'
AND scenes_categories.category_id = '8'
AND scenes.id = '1'
我如何选择必须匹配记录了所有类别ID的规定?
很确定他在找这里的动态解决方案。 – Zoidberg 2009-09-14 17:15:49
对不起,我脱下了我的downvote ...没有意识到他不想要一个OR关系 – Zoidberg 2009-09-14 17:19:43
@zoid,np,thx第二次看! – 2009-09-14 17:23:27