21

我有一个T1包含三列的表:Id, Name, Address

还有另一个T2包含 2 列的表Id, New_AddressId的列与T2的相同T1

我需要一个查询来更新with of 的Address列。T1New_AddressT2

我可以通过检查 ID 并执行更新语句来完成循环。如何必须通过查询来完成?

4

3 回答 3

18

怎么样

UPDATE T1
SET Address = T2.New_Address
FROM T2
WHERE T1.id = T2.id
于 2013-02-23T11:33:45.803 回答
10
UPDATE T1
SET T1.Address = T2.New_Address
FROM T1
INNER JOIN T2 ON T2.ID = T1.ID
于 2013-02-23T11:34:33.613 回答
4
UPDATE T1
SET Address = (select New_Address from T2 where T1.ID=T2.ID );
于 2013-02-23T11:37:58.733 回答