For following table data:

ID     | Property
1      | Sweet
2      | Sweet
2      | Sour
3      | Hot

How can I get the ID's having Property Sweet AND Sour (in this example, 2)


1 Answer 1


The easiest way would be group by and having

ID from table_name
where Property in('Sweet','Sour')
group by ID
having count(*)=2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.