SQL update多表關聯更新方法解讀
更新時間:2024年08月02日 11:02:42 作者:貓飯_ACE
這篇文章主要介紹了SQL update 多表關聯更新方法,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
1. MySQL
update test1,test2 set test1.name=test2.name,test1.age=test2.age where test1.id=test2.id
2. oracle
多表關聯,更新全表中的某一字段
- EX1:
UPDATE REDREPORT T SET T.SSHY=(SELECT D.SSHY FROM DATA_COMPANY D WHERE T.DWDM =D.DWDM and rownum=1 );
- EX2:
update test1 set (test1.name,test1.age)= (select test2.name,test2.age from test2 where test2.id=test1.id)
多表關聯,更新指定行的某一字段
UPDATE "DATA_HISTORY_copy2" t set SHJG = (select m.SHJG from DATA_MONTHCOPY m where t.DWDM = m.DWDM and SUBSTR(t.SQSJ, 0, 8) = SUBSTR(m.SQSJ, 0, 8)) WHERE EXISTS (select t.* from "DATA_HISTORY_copy2" t,DATA_MONTHCOPY m where t.DWDM = m.DWDM and SUBSTR(t.SQSJ, 0, 8) = SUBSTR(m.SQSJ, 0, 8))
3. SQLServer
update test1 set test1.name=test2.name,test1.age=test2.age from test1 inner join test2 on test1.id=test2.id
4. 通用方法
update test1 set name=(select name from test2 where test2.id=test1.id), age=(select age from test2 where test2.id=test1.id)
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Mac OS10.11下mysql5.7.12 安裝配置方法圖文教程
這篇文章主要為大家詳細介紹了Mac OS10.11下mysql5.7.12 安裝配置方法圖文教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-01-01php后臺經常提示無法連接mysql 刷新后又可以訪問的解決方法
這幾天有一臺MySQL數據庫服務器出現了頻繁的掉線情況,通過排查,并沒有排查出哪個網站被攻擊,百思不得其解中的時候,群里有個朋友說是因為微軟KB967723造成的,網上搜索了一下,果然很多人都是這樣的問題,都是windows系統下安裝的MySQL造成的2011-05-05