1

我正在 Access 2010 中编写一个 sql 查询并收到一条错误消息,指出我选择的字段用于多个关系,因此我只需要从一个表中进行选择。我认为我有正确的代码来明确告诉它从哪个表中选择,但我仍然收到该错误。

这是我的代码:

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 表示它将从成分中提取成分 ID 并忽略 BatchIngredient 吗?

4

1 回答 1

1

如果ingredientID两个表中都存在,则数据库引擎会发现这个模棱两可...

ORDER BY ingredientID

我觉得你需要...

ORDER BY I.ingredientID

我也会继续在SELECT子句中添加别名。X用适当的别名替换每个。

SELECT I.ingredientID, X.ingredientTypeCode, X.ingredientName, X.amount, X.unitCode
于 2013-08-16T21:17:13.583 回答