With the following simple table structure:
Data
----------
id
Tag
----------
id
TaggedData
----------
id
tag_id
data_id
If I had a list of Tag ids, how would I fetch every row of Data where every row of Tag in my list has a relation to a row of Data matched and not a subset thereof?
Here's the query I have right now that doesn't work:
SELECT
Data.*
FROM
Data
LEFT JOIN
TaggedData ON (Data.id = TaggedData.data_id)
LEFT JOIN
Tag ON (Tag.id = TaggedData.tag_id)
WHERE
Tag.id IN ('1' , '2')
Specifically: This one isn't working because it will return any row of Data that is related to Tag 1 or 2. Not 1 and 2.