我尝试了下面的SQL,但是出现了错误。我如何使其工作?此逻辑适用于Microsoft SQL服务器,但不适用于Oracle。
update r1
set r1.code = 7
from
(select id s1, code from table1 where code!=7) r1
inner join
(select id s2 from table2 where sub_id = '3') r2
on r1.s1 = r2.s2
错误:ORA-00933:SQL命令未正确结束
答案 0 :(得分:2)
我猜你想要一个相关的更新
update table1 t1
set t1.code = 7
where t1.code != 7
and exists( select 1
from table2 t2
where t2.sub_id = '3'
and t1.id = t2.id )