基本上 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;