I am using PostgreSQL. I have a table with three fields man, 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 as a result of which every person who has ever added carrots to a recipe should also add salt to the same recipe.
More than one person can create a recipe, in which case the person who added the ingredient will be credited for adding the ingredient. Sometimes an ingredient is used more than once, even by the same person.
If this is a 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 to get this result: face1
Because this person is the only one who added salt when adding carrots.
“Nothing but carrots can affect the result. I only need people who have added at least one carrot in one of their recipes, but I don’t want people who also did not add salt to all the same recipes that they are “Added carrots." Sorry, but I just can't explain it more clearly than that. "