SQL更新查询 [英] Sql Update Query

查看:72
本文介绍了SQL更新查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表 T1 ,其中包含三列: Id,名称,地址

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

还有另一个表 T2 ,其中包含2列 Id,New_Address T2 Id 列与 T1 的相同。

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

我需要一个查询,该查询将更新 T1 Address 列c>的 New_Address T2

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

我可以通过检查ID并执行更新语句来循环执行此操作。

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

推荐答案

怎么样

UPDATE T1
SET Address = T2.New_Address
FROM T2
WHERE T1.id = T2.id

这篇关于SQL更新查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆