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