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

 

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

 

postgresql

标准sql语句

update tableA AA set name = BB.name , sex = BB.sex  from  tableB 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 其它条件限制

 

posted @ 2019-10-10 18:11  苦涩泪滴  阅读(4636)  评论(0编辑  收藏  举报