【SQL update 多表关联更新方法总结】

柔情只为你懂 2023-09-29 10:51 70阅读 0赞

1. MySQL

  1. update test1,test2
  2. set test1.name=test2.name,test1.age=test2.age
  3. where test1.id=test2.id

2. oracle

1. 多表关联,更新全表中的某一字段
EX1:

  1. UPDATE REDREPORT T SET T.SSHY=(SELECT D.SSHY FROM DATA_COMPANY D WHERE T.DWDM =D.DWDM
  2. and rownum=1 );

EX2:

  1. update test1
  2. set (test1.name,test1.age)=
  3. (select test2.name,test2.age from test2 where test2.id=test1.id)

2. 多表关联,更新指定行的某一字段

  1. UPDATE "DATA_HISTORY_copy2" t
  2. 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))
  3. 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

  1. update test1
  2. set test1.name=test2.name,test1.age=test2.age
  3. from test1
  4. inner join test2
  5. on test1.id=test2.id

4. 通用方法

  1. update test1
  2. set name=(select name from test2 where test2.id=test1.id),
  3. age=(select age from test2 where test2.id=test1.id)

引用

【SQL】sql update 多表关联更新方法总结.

发表评论

表情:
评论列表 (有 0 条评论,70人围观)

还没有评论,来说两句吧...

相关阅读