Update 多個關聯表SQL的寫法

oracle_ace發表於2007-12-10

更新一列:
update mytab a set name=(select b.name from goal b where b.id=a.id)
where exists (select 1 from goal b where b.id=a.id);

更新多列:
update mytab a 
   set  (name,address)=(select b.name,b.address 
                                     from   goal b
                                     where  b.id=a.id)
   where  exists (select 1
                  from goal b
                  where  b.id=a.id )

特別是要注意exists後面的語句:)這會讓目標行不至於為NULL

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12361284/viewspace-349/,如需轉載,請註明出處,否則將追究法律責任。

相關文章