当前位置:Gxlcms > 数据库问题 > 【 DB_Oracle】Oracle多表关联更新

【 DB_Oracle】Oracle多表关联更新

时间:2021-07-01 10:21:17 帮助过:36人阅读

table1 t1 set t1.c= (select t2.c from table2 t2 where t1.a=t2.a) WHERE EXISTS(SELECT 1 FROM table2 t2 WHERE t2.a = t1.a);

当在t1.a=t2.a的条件下t2查询出多条记录时也会报错,此时可以考虑将t2.c唯一化。

eg1:取满足条件的t2.c的最值

update table1 t1 set t1.c = (select max(t2.c) from table2  t2 where t1.a=t2.a) where exists(select 1 from table2 t2 where t2.a = t1.a);

eg2:取满足条件第一行的t2.c值

update table1 t1 set t1.c = (select t2.c  from table2  t2 where t1.a=t2.a  and rownum =1) where exists(select 1 from table2 t2 where t2.a = t1.a);

参考博文:ORACLE 两表关联更新三种方式

【 DB_Oracle】Oracle多表关联更新

标签:博文   写法   mamicode   常见   one   blog   html   div   sts   

人气教程排行