我有 2 张桌子:
pages 表包含字段id
pages2categories 表包含字段page
和category
我想从 pages 表中选择记录
where (there is a record in the pages2categories table
WHERE pages2categories::page = pages::id AND pages2categories:: category = 'X')
AND (there is also a record in the pages2categories table WHERE pages2categories::page = pages::id AND pages2categories:: category = 'Y')
AND (there is also a record in the pages2categories table WHERE pages2categories::page = pages::id AND pages2categories:: category = 'Z')
换句话说,只有当所有三个匹配记录都存在于 pages2categories 表中时,才从 pages 表中返回一条记录。
例子:
页面::id
1
2
3
pages2categories::page, pages2categories::category
1, x
1, y
2, x
2, y
2, z
3, x
结果应该只返回 pages 表中的记录 2。
我希望这很清楚。谢谢!