實際工作中常出現根據一個表的內容更新另一個表的內容,不同數據庫直接的寫法也有不同地方,總結一下 :
不同數據庫的更新數據:
ORACLE:
update TBALE1 set COL =
(select COL from TBALE2 where TBALE1.COL1 = TBALE2.COL1)
where exists (select 1 from TBALE2 where TBALE1.COL1 = TBALE2.COL1)
mysql:
UPDATE t1 set name = (select name from t2 where t1.id = t2.id)
update table_1 t1,table_2 t2 set t1.column = t2.column where t1.id = t2.pid;