I have 2 tables:
pages table contains field id
pages2categories table contains fields page and category
I want to select records from the pages table
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')
In other words, returning a record from the pages table only if all three matching records exist in the pages2categories table.
EXAMPLE:
pages::id
1
2
3
pages2categories::page, pages2categories::category
1, x
1, y
2, x
2, y
2, z
3, x
Result should return just record 2 from the pages table.
I hope this is clear. Thanks!
You can also use this: