I have two tables as follows:
table: recipe
fields: recipe_ID, title
table: recipe_ingredient
fields: recipe_ID, ingredient_ID
I would like to show only recipes which contain certain ingredients (I managed to do that part), however I also want to exclude recipes which contain certain ingredients.
So far I managed to do this query, it is working but it only shows recipes which contain certain ingredients.
SELECT DISTINCT r.recipe_ID, r.title
FROM recipe r
JOIN recipe_ingredient ri ON (ri.recipe_ID = r.recipe_ID)
WHERE ri.ingredient_ID IN (4, 7)
GROUP BY r.recipe_ID
HAVING COUNT(ri.ingredient_ID) = 2
How do I make it to also exclude recipes with certain ingredients? I tried some methods but I failed.
Note: The 4, 7 and Count values are static for demonstration purposes.
Please ask if you need any more info or anything.
Thanks a lot!