I have two tables in my SQLLite database. I am trying to get back the drinks that can be made with the ingredients typed in.
I am trying to formulate this query to get what I want.
Table Drinks
Columns
drink_id | title | ingredients | directions | ingredientsNum
Sample row looks like
1 | Papa Smurf | 1 crushed blue popsicle, 8 oz Kool-Aid , 4 oz vodka | The directions | 3
Table Ingredients
Columns
drink_id | ingredient
Sample row looks like
1 | blue popsicle
My Query at the moment
This is my partial pseudocode at what I want to return (after I get this I’ll dynamically put in terms to query).
I want to return all drinks that have the amount of inputs to be equal to or more than the drinks ingredient number, and those inputted ingredients match all the ingredients needed in the drink.
SELECT drinks.title, drinks.ingredients, drinks.directions
FROM drinks, (SELECT count(ingredients._id) as ingredientNumber FROM ingredients
WHERE ingredients.ingredient LIKE '%rum%'
GROUP BY ingredients._id) as foundIngredients
WHERE drinks.ingredientsNum = foundIngredients.ingredientNumber;
Query reflecting clarified question:
Similarly, if you allow a drink to have extra ingredients besides all specified: