數據庫根據表的某一字段更新其他表內容

實際工作中常出現根據一個表的內容更新另一個表的內容,不同數據庫直接的寫法也有不同地方,總結一下 :

不同數據庫的更新數據:

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;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章