I’m doing a project about cooking recipes with PHP(with Codeigniter) and MYSQL.
I have three tables:
Ingredients–id,name.Recipe–id,nameing_to_rep–recipe_id,ingredient_id(I use this table for holding which recipe has which ingredients.)
What is the query for “get all recipes which have eggs (id = 64) and salt (id = 65)”
I tried:
SELECT * FROM recipe JOIN ing_to_rep ON recipe.id = ing_to_rep.rep_id
WHERE ing_to_rep.ing_id = 64 AND ing_to_rep.ing_id = 65
Naturally, it returns nothing but it helps you to get what I’m trying to do.
There is probably a more efficient way and a more flexible way, but two subquery joins will do:
Also can be done with
EXISTS