I have the following table
|------------------------| | owner | animal | color | |------------------------| | John | dog | black | | Peter | dog | brown | | John | cat | green | | Lisa | dog | white | | Peter | cat | black | |------------------------|
I need to return which owner has a black dog AND a green cat, the result must be 'John'
I tried this with no luck
SELECT owner FROM pets WHERE ( EXISTS ( SELECT * FROM pets WHERE animal = 'dog' AND color = 'black' ) AND EXISTS ( SELECT * FROM pets WHERE animal = 'cat' AND color = 'green' ) )