It happens every time. Not as straightforward as I expected.
First, donβt do the βLIKEβ statement if it is an exact match. Such statements are less effective than direct comparison.
Secondly, you can accomplish what you request in the GROUP BY / HAVING clause:
SELECT masteritemid FROM itemsgrouptable GROUP BY masteritemid HAVING COUNT(itemname) = 4 WHERE itemname IN ('Item 1','Item 2','Item 3','Item 4')
Basically you group all your objects with masteritemid and limit this grouped set where all 4 (or any number of "item #" matches) are within your specified "IN" clause. Kind of a neat trick.
source share