SQL两表之间:根据⼀个表的字段更新另⼀个表的字段1. 写法轻松,更新效率⾼:
update table1
set field1=table2.field1,
field2=table2.field2
记住我from table2
where table1.id=table2.id
update chq_gx_empinfo  set
deptzz = chq_gx_empinfo2.deptzz,deptname =chq_gx_empinfo2.deptname
from chq_gx_empinfo2 where chq_pno = chq_pno
and chq_pno in ('CHQS2076','CHQS1959')
2. 常规⽅式,种写法相当于⼀个 Left join,以外⾯的where为更新条数,如果不加where就是所有记录
update table1
set field1=(select top 1 field1 from table2 where table2.id=table1.id)
where table1.id in (condition)