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-01
php后台经常提示无法连接mysql 刷新后又可以访问的解决方法
这几天有一台MySQL数据库服务器出现了频繁的掉线情况,通过排查,并没有排查出哪个网站被攻击,百思不得其解中的时候,群里有个朋友说是因为微软KB967723造成的,网上搜索了一下,果然很多人都是这样的问题,都是windows系统下安装的MySQL造成的2011-05-05


最新评论