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 = '北京'