0

I have made this sql and I need to update table with given result

SELECT DISTINCT t1.t1_val3, t1.t1_val4 DECODE (b_val, 'A', 'Its A', 'B', 'Its B', 'C', 'Its C', NULL ) decode_val, FROM t1, t2, t3 WHERE t1.t1_val = t2.t2_val AND t2.t2_val = t3.t3_val AND t3.t3_val2 <> 'PSA' AND t3.t3_val2 = 'Y' 

Now using this query I need to update t1 table.

something like this,

update t1 set t1.val5=decode_val where t1.t1_val3= value returned from above query(first column t1_val3) and t1.t1_val4= value returned from above query(2nd column t1_val4) 

DB - 10g

0

2 Answers 2

2

Since you are on 10g, the MATCHED and NOT MATCHED clauses are now optional.

MERGE INTO t1 a USING (SELECT DISTINCT t1.t1_val3, t1.t1_val4 DECODE (b_val, 'A', 'Its A', 'B', 'Its B', 'C', 'Its C', NULL ) decode_val, FROM t1, t2, t3 WHERE t1.t1_val = t2.t2_val AND t2.t2_val = t3.t3_val AND t3.t3_val2 <> 'PSA' AND t3.t3_val2 = 'Y') b ON(a.t1_val3 = b.t1_val_3 and a.t1_val4 = b.t1_val4) WHEN MATCHED THEN UPDATE SET a.t1.val5 = b.decode_val 
Sign up to request clarification or add additional context in comments.

Comments

1

Try this :

update t1 set t1.val5 =DECODE (b_val, 'A', 'Its A', 'B', 'Its B', 'C', 'Its C', NULL ) FROM t1, t2, t3 WHERE t1.t1_val = t2.t2_val AND t2.t2_val = t3.t3_val AND t3.t3_val2 <> 'PSA' AND t3.t3_val2 = 'Y' 

5 Comments

Please verify your post before submitting, always use code tags and check if the tags are properly applied.
im new here.sorry :)
No problem. I have edited your answer.
mark it as Answer ,this may help someone
I have voted up for your answer and marked lalit's solution as answer, he provided solution earlier. Thanks :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.