PostgreSQL - select only when specific multiple apperance in column
Posted
by
Horse SMith
on Stack Overflow
See other posts from Stack Overflow
or by Horse SMith
Published on 2012-10-31T16:59:11Z
Indexed on
2012/10/31
17:00 UTC
Read the original article
Hit count: 232
I'm using PostgreSQL. I have a table with 3 fields person, recipe and ingredient
person = creator of the recipe
recipe = the recipe
ingredient = one of the ingredients in the recipe
I want to create a query which results in every person who whenever has added carrot to a recipe, the person must also have added salt to the same recipe.
More than one person can have created the recipe, in which case the person who added the ingredient will be credited for adding the ingredient. Sometimes the ingredient is used more than once, even by the same person.
If this the table:
person1, rec1, carrot
person1, rec1, salt
person1, rec1, salt
person1, rec2, salt
person1, rec2, pepper
person2, rec1, carrot
person2, rec1, salt
person2, rec2, carrot
person2, rec2, pepper
person3, rec1, sugar
person3, rec1, carrot
Then I want this result: person1
Because this person is the only one who whenever has added carrot also have added salt.
© Stack Overflow or respective owner