Oracle 实现多表参照更新
参照T2 修改 T1
表1
表2
- 方法1
update student set grade=(select grade from gradedetial where sid=student.id and rownum=1)
where exists(select count(1) from gradedetial where sid=student.id)
如果同时更新多个字段可以参照语法:
update tb1 t1 set(字段1,字段2,...)=(select 字段1,字段2... from tb2 t2 where t2.id=t2.id)
where exists(select count(1) from t2 where t2.id=t1.id)
- 方法2 内联视图更新(要求取数据的表即T2,该字段必须是主键或者有唯一约束),上表不具备这个条件,因此这个方法在这里会失败!
update (select a.grade grade1,b.grade grade2 from student a inner join gradedetial b
on a.id=b.sid) t
set grade1=grade2;
标签:grade,t2,更新,查询,student,联接,where,id,select
From: https://www.cnblogs.com/sundh1981/p/17467282.html