0
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.

1 Answer 1

1

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;
Sign up to request clarification or add additional context in comments.

3 Comments

But where is t2.a1 is used. I dont see that in your SQL. In my SQL thats where I have the value? Am I missing something.
I changed this, tgt.a1 = src.t1_a1 to tgt.a1=src.t2_a1. And it worked fine. One more correction I did. In my original SQL tgt.a1 = src.t1_a1 was not primary id. So I changed it to get primary ID and afterwards it worked just fine. Thanks
Yes, sorry - I made a typo. You got it right - it should have been tgt.a1 = src.t2_a1. I've corrected that now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.