0

I have 3 tables:

  • Recipes (id, name)
  • Recipes_Ingredients(id, fk_recipe, fk_ingredient, quantity)
  • Ingredients (id, name)

I need to find all the recipes that containing exactly a provided list of ingredients ID.

Es:

I provide a list of ingredients id like 111 (salt), 222(pepper), 333(oil) and I need to find all the recipes that have ONLY these ingredients.

So if a recipe has those ingredients (the id list I provided) + other ingredients, it doesn't have to show

Thanks in advance!

Shadow
  • 33,525
  • 10
  • 51
  • 64

1 Answers1

0
SELECT fk_recipe
FROM Recipes_Ingredients
GROUP BY fk_recipe
HAVING SUM(fk_ingredient IN (111,222,333)) = COUNT(*)
Akina
  • 39,301
  • 5
  • 14
  • 25