update批量更新某一列成其它列对应的值【原】

时间:2023-03-09 19:20:43
update批量更新某一列成其它列对应的值【原】

update批量更新某一列成其它列对应的值

postgresql

标准sql语句

update AA set name = BB.name , AA.sex = BB.sex  from  BB where AA.id = BB.id ;

注意不要写成 from AA,BB ,即不要把自身的表写在from后,不然会报异常 :table name specified more than once

update AA set name = BB.name from AA,BB where AA.id = BB.id 

也不要在set 后的列名上加 别名 , 即不要有AA.name , 不然会报异常: column "name" of relation "AA" does not exist

update AA set AA.name = BB.name , AA.sex = BB.sex  from  BB where AA.id = BB.id ;

oracle

标准sql语句,可以同时更新多个列

UPDATE BB set (name,sex) = (select CC.name, CC.sex from CC where CC.id = BB.id) where BB.id = 1

SQL Server

update A SET A.COL1=B.COL1  FROM A,B where A.KEY=B.KEY where 其它条件限制