多表关联执行update
1.仅在where子句中连接
--table2中全部为优秀学生,将table1中的优秀学生的成绩更新为优
update table1 t1 set t1.grade = '优'
where exists (
select 1 from table2 t2 where t2.id = t1.id
);
2.update的值来自另一个表
看完以下例子,你就会明白了。
示例:表t_tst_bkin存储了银行联行行号及其上级机构的联行行号,现在需要将每个银行的总部的联行行号维护进sup_lbnk_no字段
初始化sql:
--创建表
create table t_tst_bkin
( lbnk_no varchar2(12) not null enable,
lbnk_nm varchar2(256) not null enable,
up_lbnk_no varchar2(12) not null enable,
sup_lbnk_no varchar2(12),
primary key (lbnk_no)
);
comment on table t_tst_bkin is '联行行号信息表';
comment on column t_tst_bkin.lbnk_no is '支付行号';
comment on column t_tst_bkin.lbnk_nm is '机构名称';
comment on column t_tst_bkin.up_lbnk_no is '上级机构支付行号';
comment on column t_tst_bkin.sup_lbnk_no is '总部支付行号';
<