I need to receive claims (of a customer) who has only specific types of products (productid IN(1,2)). There are different other products but I need only the ones with type 1 and 2 (who would have both at the same time). Client might have other products as well but important to take the ones who have 1&2
Example
clientID claimID productID
123 333 1
123 333 2
123 333 4
123 333 6
123 333 7
>Solution :
SELECT C.clientID
FROM YOUR_TABLE AS C
WHERE C.productID IN(1,2)
GROUP BY C.clientID
HAVING COUNT(DISTINCT C.productID)=2