我有两个表Recipes
和Ingredients
,并且我有一个简单的子查询,如下:
SELECT
RecipeTitle
FROM
Recipes
WHERE
Recipes.RecipeID IN (
SELECT
RecipeID
FROM
Ingredients
)
我想知道为什么上面的sql没问题,因为Ingredients
没有RecipeID
列,所以当我运行以下查询时:
SELECT
RecipeID
FROM
Ingredients
发生错误,说Unknown column 'RecipeID' in 'field list'
。
在这里更新:
不会引起Unknown column 'RecipeID' in 'field list'
,如下所示:
SELECT
RecipeTitle
FROM
Recipes
WHERE
Recipes.RecipeID/*1*/ IN (
SELECT
RecipeID /*no problem if this is the same as 1 in above line*/
FROM
Ingredients
)