2013-08-16 14 views
1

我在Access 2010中编写了一个sql查询,并得到一条错误消息,说我选择的字段在多个关系中使用,所以我需要从一个表中选择。我以为我有正确的代码,明确告诉它哪个表可以选择,但我仍然得到这个错误。编码时出错(多重关系)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说,它将从成分拉ingredientID而忽略BatchIngredient?

+1

这两个表中是否存在更多字段名称? – William

+0

Just ingredientID包含在两个表中。 – Jonathan

回答

1

如果ingredientID存在两个表中,数据库引擎会发现这个暧昧......

ORDER BY ingredientID 

我想你需要...

ORDER BY I.ingredientID 

我只想继续前进,添加SELECT子句中的别名也一样。将每个X替换为适当的别名。

SELECT I.ingredientID, X.ingredientTypeCode, X.ingredientName, X.amount, X.unitCode 
+0

太棒了!通过添加“I”。进入它的ORDER BY语句。谢谢! – Jonathan