如何在更新后的表上使用多个联接更新 SQL Server 上的表?在 MySQL 中,您可以为更新的表定义别名,但它如何与 TSQL 一起使用。
UPDATE recert.ou --#1-- In MSSQL/TSQL no alias allowed
SET parent_id = o2.ID
FROM recert.ou as O
JOIN recert.country C ON C.ID = O.country_id
JOIN recert.ou P ON O.parent_id = P.ID and p.country_id <> O.country_id
JOIN recert.ou o2 on o2.name = p.name and c.ID = o2.country_id
JOIN recert.country as c2 on c2.ID = o2.country_id
WHERE O.ID = o2.ID
-
RESULT: *The table 'o' is ambiguous.*