tableA 表某个字段更新条件与tableB相关时,可以使用update select结合方式
一、Oracle语句
1、更新单个字段

update tableA a set a.id = (select b.id from tableB b where b.id = a.id)
where a.id in (select b.id from tableB b where b.id = a.id and b.city = '北京')

2、更新多个字段

update tableA a set (a.localname,b.phone) = (select b.localname,b.phone from tableB b where b.id = a.id)
where a.id in (select b.id from tableB b where b.id = a.id and b.city = '北京')

二、Sql Server语句
1、单个字段

update tableA a set a.localname = b.localname from tableA a,tableB b
where a.id = b.id

2、多个字段

update tableA a set a.localname = b.localname, a.phone = b.phone from tableA a,tableB b
where a.id = b.id and b.city = '北京'
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐