sql 关联了2张表的 update 语句(转)

转自SQL Update:使用一个表的数据更新另一张表 update 关联两个表

基本上 select 能支持的关联和子查询操作,都能在 update 语句中使用。

在 where 条件中使用子查询

update a
set a.age =1
where id in (select device_id from b)

在 where 条件和 set 语句中同时使用子查询

update a
set a.gender = (select sex from b where a.id= b.stu_id) 
where id in (select stu_id from b)

连接(join)

表结构

用表B的数据(mc列)更新表A的mc列

SQL Server

update A SET A.mc = b.mc FROM A ,B WHERE  A.bmbh = B.bmbh and A.xmbh = B.xmbh;

Access

update A, B  set A.mc = B.mc where A.bmbh = B.bmbh and A.xmbh = B.xmbh;

update A INNER JOIN B ON A.bmbh = B.bmbh AND A.xmbh = B.xmbh SET A.mc = B.mc;

转自SQL Update:使用一个表的数据更新另一张表 update 关联两个表

猜你喜欢

转载自blog.csdn.net/qq_41767116/article/details/132074945