I have following two tables
Table 1: creatives
creative_id creative_name
1 xyz
2 pqr
3 abc
Table 2: term_relationships
creative_id term_id
1 1
1 2
1 3
2 1
2 2
2 4
3 1
3 2
3 3
I want to join the above 2 tables to get query output containing creatives for which term_id = 1 AND 2 AND 3 must exists. For the above example, only creatives 1 (aka xyz) and 3 (aka abc) must be present in the query output since creative 2 does not satisfy the above condition.
So
SELECT *
FROM term_id INNER JOIN
creatives ON term_id.creative_id = creatives.creative_id
WHERE ????
What should the where
clause look like?
One way to do this is to count the number of matching terms and check it sums up to the number of matches you want: