I have the following tables.
Table Name: Recipe
id topic description difficultylevel totaltime
1 Cheese Cheese Easy 10
2 Cheese1 Cheese1 Medium 50
Table Name: Ingredients
id recipeid ingredient
1 1 Butter
2 1 Cheese
3 1 Bread
Now, when I run the following query, it returns the recipe id = "1", although it should not, because I do not want a recipe in which there is butter.
SELECT recipe.id
FROM
`recipe`
INNER JOIN ingredients ON recipe.id = ingredients.recipeid
WHERE
(recipe.description LIKE '%CHEESE%' OR recipe.topic LIKE '%CHEESE%')
AND (recipe.difficultylevel='Easy')
AND (recipe.totaltime <= 30)
AND (ingredients.ingredient <> 'Butter')
It returns recipe.id = "1" twice because of cheese and bread. I need to fix the query so that it doesn't include recipe.id = "1" at all if it has Butter (for example)
source
share