SQL 中未绑定的多部分标识符列
Multipart identifier column not bound in SQL
请你帮忙。我正在尝试执行以下操作:
Select tb4.columnName As test1,
tb2.columnName As test2,
tb4.columnName As test3
from [dbname].Table2 tb2, Table1 tb1
JOIN Table3 tb3 ON tb3.ColumnName = tb1.columnName
JOIN Table4 tb4 ON tb4.ColumnName = tb3.columnName
JOIN [dbname].Table5 tb5 ON tb5.ColumnName = **tb2.ColumnName**
我得到:
multipart identifier not bound error at ‘tb2.ColumnName’
切勿混用隐式连接(在 from
子句中使用逗号)和显式连接(使用 join ... on
语法)。它们具有不同的优先级,因此在评估最后一个连接条件时,数据库还不知道 tb2
。
事实上,始终使用显式连接:几十年来它们一直是标准。您现有的查询似乎缺少 tb2
和 tb1
之间的连接条件,但您想要的逻辑应该是:
select
tb4.columnName As test1,
tb2.columnName As test2,
tb4.columnName As test3
from Table2 tb2
inner join Table1 tb1 on ?? -- join condition here
inner join Table3 tb3 on tb3.ColumnName = tb1.columnName
inner join Table4 tb4 on tb4.ColumnName = tb3.columnName
inner join Table5 tb5 on tb5.ColumnName = tb2.ColumnName
我想这就是您要找的。而且,您在 select 语句中有两次 tb4.columnName
。
Select tb4.columnName As test1,
tb2.columnName As test2,
tb4.columnName As test3
from [dbname].Table2 tb2
JOIN [dbname].Table5 tb5 ON tb5.ColumnName = tb2.ColumnName
JOIN Table1 tb1 ON tb2.ColumnName = tb1.ColumnName
JOIN Table3 tb3 ON tb3.ColumnName = tb1.columnName
JOIN Table4 tb4 ON tb4.ColumnName = tb3.columnName
请你帮忙。我正在尝试执行以下操作:
Select tb4.columnName As test1,
tb2.columnName As test2,
tb4.columnName As test3
from [dbname].Table2 tb2, Table1 tb1
JOIN Table3 tb3 ON tb3.ColumnName = tb1.columnName
JOIN Table4 tb4 ON tb4.ColumnName = tb3.columnName
JOIN [dbname].Table5 tb5 ON tb5.ColumnName = **tb2.ColumnName**
我得到:
multipart identifier not bound error at ‘tb2.ColumnName’
切勿混用隐式连接(在 from
子句中使用逗号)和显式连接(使用 join ... on
语法)。它们具有不同的优先级,因此在评估最后一个连接条件时,数据库还不知道 tb2
。
事实上,始终使用显式连接:几十年来它们一直是标准。您现有的查询似乎缺少 tb2
和 tb1
之间的连接条件,但您想要的逻辑应该是:
select
tb4.columnName As test1,
tb2.columnName As test2,
tb4.columnName As test3
from Table2 tb2
inner join Table1 tb1 on ?? -- join condition here
inner join Table3 tb3 on tb3.ColumnName = tb1.columnName
inner join Table4 tb4 on tb4.ColumnName = tb3.columnName
inner join Table5 tb5 on tb5.ColumnName = tb2.ColumnName
我想这就是您要找的。而且,您在 select 语句中有两次 tb4.columnName
。
Select tb4.columnName As test1,
tb2.columnName As test2,
tb4.columnName As test3
from [dbname].Table2 tb2
JOIN [dbname].Table5 tb5 ON tb5.ColumnName = tb2.ColumnName
JOIN Table1 tb1 ON tb2.ColumnName = tb1.ColumnName
JOIN Table3 tb3 ON tb3.ColumnName = tb1.columnName
JOIN Table4 tb4 ON tb4.ColumnName = tb3.columnName