I am working on an application to dispense liquids. here is the organization of the DB
CANISTER:
- canister_id{PK}
- ingredient_id{FK}
INGREDIENT:
- ingredient_id{PK}
- ingredient_name
DRINK:
- drink_id{PK}
- drink_name
INGREDIENTINSTANCE:
- instance_id{PK}
- drink_id{FK}
- ingredient_id{FK}
- amount
Each drink has multiple ingredients(held in the ingredientInstance table), but there are only 12 canisters. I am trying to write an SQL command that will gather all drinks that have ALL of their required ingredients currently in canisters.
So far, this is what I have.
SELECT DISTINCT Drink.drink_name
FROM Drink, ingredientInstance, Canister
WHERE (((ingredientInstance.drink_id)=[Drink].[drink_id])
AND ((ingredientInstance.ingredient_id)
IN (select ingredient_id FROM Canister)));
However, this is returning all drinks that have even a single ingredient available. What I am looking for is a way to ensure that for every associated ingredient in ingredientInstance, it is currently in a canister.
For example, let's say that drink1 requires ingredient1 and ingredient2. I want it to appear in the result if both of those ingredient IDs are present in the Canisters, but not if only one or zero ingredients are in the canister.
I'm sure it's something obvious, but I can't think of how to do this.