【发布时间】:2018-01-24 00:52:24
【问题描述】:
SELECT
Recipes.RecipeID, Recipes.RecipeTitle
FROM
Recipes
INNER JOIN
Recipe_Ingredients ON Recipes.RecipeID = Recipe_Ingredients.RecipeID
INNER JOIN
Ingredients ON Ingredients.IngredientID = Recipe_Ingredients.IngredientID
WHERE
(Ingredients.IngredientName = 'Beef')
AND (Ingredients.IngredientName = 'Garlic')
此 SQL 查询不返回任何内容。然而,当我单独/单独检查 where 条件而不将它们与 AND 放在一起时,他们提出了一个名为“烤牛肉”的食谱,实际上既有牛肉又有大蒜。因此,它不应该在结果中显示为 1 行。但它没有显示任何东西。为什么?
【问题讨论】:
-
请在下面尝试 SELECT Recipes.RecipeID, Recipes.RecipeTitle FROM Recipes INNER JOIN Recipe_Ingredients ON Recipes.RecipeID = Recipe_Ingredients.RecipeID INNER JOIN Ingredients ON Ingredients.IngredientID = Recipe_Ingredients.IngredientID WHERE Ingredients.IngredientName = 'Beef ' 和 Ingredients.IngredientName = '大蒜'
-
成分名称不可能同时是牛肉和大蒜。 AND在句子中使用时是什么意思?
-
在
where子句中将and替换为or
标签: sql sql-server inner-join where