Reputation: 67
select distinct T1.a1, T2.a1
from T1, T2, T3 where
T2.name='Something' and T2.value is not null and
T2.a1=T3.a1 and T1.a2=T3.a2 and
T1.a3='Something' and T1.a4 is null
I have values populated in T2 and its missing in T1.
I have to update T1 value with T2 value. The SELECT sql is bringing values properly. But I am not able to come up with the UPDATE sql for ORACLE database.
Upvotes: 0
Views: 1843
Reputation: 23578
Try a MERGE:
merge into t1 tgt
using (select distinct t1.a1 t1_a1, t2.a1 t2_a1
from t1,
t2,
t3
where t2.name='Something'
and t2.value is not null
and t2.a1=t3.a1
and t1.a2=t3.a2
and t1.a3='Something'
and t1.a4 is null) src
on (tgt.a1 = src.t1_a1)
when matched then
update set tgt.a1 = src.t2_a1;
Upvotes: 1