编写SQL时出错(多个关系)
我正在Access 2010中编写一个sql查询,收到一条错误消息,说我选择的字段用于多个关系,所以我只需要从一个表中选择。我认为我有正确的代码来明确地告诉它从哪个表中选择,但我仍然得到那个错误 这是我的代码:编写SQL时出错(多个关系),sql,ms-access,ms-access-2010,Sql,Ms Access,Ms Access 2010,我正在Access 2010中编写一个sql查询,收到一条错误消息,说我选择的字段用于多个关系,所以我只需要从一个表中选择。我认为我有正确的代码来明确地告诉它从哪个表中选择,但我仍然得到那个错误 这是我的代码: SELECT I.ingredientID, ingredientTypeCode, ingredientName, amount, unitCode FROM Ingredient AS I INNER JOIN BatchIngredient AS B ON I.ingredient
SELECT I.ingredientID, ingredientTypeCode, ingredientName, amount, unitCode
FROM Ingredient AS I
INNER JOIN BatchIngredient AS B ON I.ingredientID=B.ingredientID
ORDER BY ingredientID;
指定I.ingredientID不应该说它将从配料中提取ingredientID并忽略BatchComponent吗?如果两个表中都存在
ingredientID
,db引擎将发现这一点不明确
ORDER BY ingredientID
我想你需要
ORDER BY I.ingredientID
我会继续在SELECT
子句中添加别名。用适当的别名替换每个X
SELECT I.ingredientID, X.ingredientTypeCode, X.ingredientName, X.amount, X.unitCode
如果两个表中都存在
ingredientID
,则db引擎会发现此值不明确
ORDER BY ingredientID
我想你需要
ORDER BY I.ingredientID
我会继续在SELECT
子句中添加别名。用适当的别名替换每个X
SELECT I.ingredientID, X.ingredientTypeCode, X.ingredientName, X.amount, X.unitCode
两个表中出现的字段名是否更多?两个表中都包含IngRedentid。两个表中出现的字段名是否更多?两个表中都包含IngRedentid。太好了!通过在ORDERBY语句中添加“I.”,它起了作用。非常感谢。伟大的通过在ORDERBY语句中添加“I.”,它起了作用。非常感谢。