查询获得鸡尾酒列表给出的成分 [英] Query to get list of cocktails given ingredients
问题描述
我正在尝试写一个查询,以获得一份含有一种或多种所选成分的饮料配方....
所以,在一个搜索表单我希望能够选择一种或多种成分,并使用该成分组合返回所有饮料。
我有3个表格(此处仅显示相关字段):
tDrinks
-drinkid
-drinkname
-drinkdesc
tIngredients (查询中不需要,但在其他地方使用)
-ingredientid
-ingredientname
< b> tDrinkIngredients
-drinkid
-ingredientid
-qty
so ,我可以得到一个饮料清单给出一个成分:
Hi, I''m trying to write a query to get a list of drink recipes which have one or more of the selected ingredients....
so, in a search form I want to be able to choose 1 or more ingredients and have sql return all drinks with that combination of ingredients.
I have 3 tables (only relevant fields shown here):
tDrinks
-drinkid
-drinkname
-drinkdesc
tIngredients (not needed in the query but used elsewhere)
-ingredientid
-ingredientname
tDrinkIngredients
-drinkid
-ingredientid
-qty
so, I can get a list of drinks given one ingredient:
推荐答案
你不想得到一份与所有>所有给定成分或其中一种成分相匹配的饮料清单吗?
如果它是第一个一,你可以尝试使用INNER JOIN,并在ON子句中指定你想要的所有成分。
这只是你发布的查询的一个小修改。 (我重新格式化了一下):
Do you wan''t to get a list of drinks that match all the given ingredients or just one of them?
If it''s the first one, you could try using a INNER JOIN, and specify all the ingredients you want in the ON clause.
It''s only a small modification to the query you posted. (I reformatted it a bit to):
您好,感谢您的快速回复......是的,我想要只有在搜索到所有成分的情况下才能获得饮料....
你给的第二个例子非常适合获取任何一种成分,但我似乎无法得到第一个查询工作......这里有一些关于表结构的更多信息,所以希望有人可以帮助我:
Hi, thanks for the quick response...yes, I want to get drinks only if they have ALL the ingredients searched for....
the second example you gave works great for getting any one ingredient, but I can''t seem to get the first query working......here is some more information on the structure of the tables so hopefully someone can help me:
第一个查询有什么问题?
它是如何起作用的?
What''s the problem with the first query?
How is it not working?
这篇关于查询获得鸡尾酒列表给出的成分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!