使用别名表更新 SQL 仍然返回“表不明确";错误 [英] Update SQL with Aliased tables still returns "table is ambiguous" error
问题描述
我正在尝试运行以下更新,但遇到表不明确"错误.
I am trying to run the below update but running into the "table is ambiguous" error.
UPDATE dbo.cg
SET cg.column = gId.ID
FROM dbo.a
INNER JOIN dbo.cg as cId ON cId.[a] = dbo.a.[c]
INNER JOIN dbo.cg as gId ON gId.[a] = dbo.a.[b];
表 dbo.a 包含用于更新 cg 中的值的数据,这些数据基于与同一表相对于不同列中的值的关系.这是一个自引用层次结构.
The table dbo.a contains data to update a value in cg based on a relationship to same table against a value in a different column. It is a self-referencing hierarchy.
正如你所看到的,一切都是别名,所以我有点困惑为什么这不会运行.
As you can see, everything is aliased so I am a bit confused why this won't run.
非常感谢您提供的任何帮助.
Many thanks in advance for any help that can be provided.
推荐答案
在 SQL Server 中,您应该在 update
而不是表中使用 alias.此外,您没有名为 cg
的别名.所以是这样的:
In SQL Server, you should use the alias in the update
, not the table. In addition, you have no alias called cg
. So something like this:
UPDATE cId
SET column = gId.ID
FROM dbo.a a INNER JOIN
dbo.cg cId
ON cId.[a] = a.[c] INNER JOIN
dbo.cg gId
ON gId.[a] = a.[b];
这篇关于使用别名表更新 SQL 仍然返回“表不明确";错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!