Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
编写SQL时出错(多个关系)_Sql_Ms Access_Ms Access 2010 - Fatal编程技术网

编写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

我正在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不应该说它将从配料中提取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.”,它起了作用。非常感谢。