Sql Update Query [duplicate]

2020-04-02 01:43发布

I have a table T1 which contains three columns: Id, Name, Address

There is another table T2 which contains 2 columns Id, New_Address. Id column of T2 is same as of T1.

I need a query which will update Address column of T1 with New_Address of T2.

I can do it through a loop by checking ID and executing update statement. How can it has to be done with a query?

3条回答
够拽才男人
2楼-- · 2020-04-02 02:08

How about

UPDATE T1
SET Address = T2.New_Address
FROM T2
WHERE T1.id = T2.id
查看更多
放我归山
3楼-- · 2020-04-02 02:09
UPDATE T1
SET T1.Address = T2.New_Address
FROM T1
INNER JOIN T2 ON T2.ID = T1.ID
查看更多
Deceive 欺骗
4楼-- · 2020-04-02 02:21
UPDATE T1
SET Address = (select New_Address from T2 where T1.ID=T2.ID );
查看更多
登录 后发表回答