lundi 5 janvier 2015

Database Selecting Multiple Rows Based on Multiple Values

I am designing a database to store cocktail name and their ingredients. The database has following structure.



Drinks
ID NAME IMGURL
1 A http://
2 B http://
3 C http://

Ingredients
ID NAME
1 Water
2 SugarSyrup
3 Rum
4 Vodka
5 Gin
6 Tonic
7 Orange Juice
8 Whiskey

DRINKS_INGREDIENTS
ID DRINKSID INGREDIENTSID Quantity
1 1 1 30
2 1 4 90
3 1 6 60
4 2 8 30
5 2 1 30
6 2 2 30
7 2 3 10
8 2 4 30
9 3 5 60
10 3 6 60


I want to select only the DRINKSIDs from DRINKS_INGREDIENTS table where the ingredients equals to the ones we have in stock.ex- if we only have Gin and Tonic in Stock, then it should return only DrinkID=3.If we have all the ingredients in stock, then it will return the all the DrinkIDs in the list.


I am using sqlite database and I am not sure how to write a query to make this work.


Any help is appreciated.


Aucun commentaire:

Enregistrer un commentaire