17,377
社区成员
发帖
与我相关
我的任务
分享
update table1 a set (a.bbb,a.ccc)=(select b.bbb2,b.bbb2 from table2 b where b.id2=a.id1 and b.aaa=a.aaa)
where exists
(select 1 from table2 c
where a.id1=c.id2 and a.aaa=c.aaa)
--如果是10g或是以上版本的话可以用merge into
merge into table1
using table2
on(table1.id1=table2.id2 and table1.aaa=table2.aaa)
when matched then
update
set table1.bbb=table2.bbb2 ,table1.ccc=table2.ccc;
when not matched then
insert
values(table2.id2,table2.bbb2);
--这样试试
update table1 set bbb=(select bbb2 from table2
where table1.id=table2.id and table1.aaa=table2.aaa)
where exists(select null from table2
where table1.id=table2.id and table1.aaa=table2.aaa)