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 其它条件限制

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM