0
create table table1(accountno number);
insert into table1  values (1);
insert into table1 values (2);
insert into table1 values (3);
insert into table1 values (4);
insert into table1 values (5);
insert into table1 values (6);

create table table2(accountno number,check_y_n varchar2(20));

insert into table2 (accountno)  values (4);
insert into table2 (accountno) values (5);
insert into table2 (accountno) values (6);
insert into table2 (accountno) values (7);
insert into table2 (accountno) values (8);
insert into table2 (accountno) values (9);

I need below two update query in single query using joins. Can anyone help me on this

UPDATE TABLE2 SET check_y_n ='YES' WHERE accountno IN (SELECT accountno FROM TABLE1);

UPDATE TABLE2 SET check_y_n ='NO' WHERE accountno NOT IN (SELECT accountno FROM TABLE1);

1 Answer 1

1

Use a CASE expression:

UPDATE TABLE2
SET check_y_n = CASE
                WHEN accountno IN (SELECT accountno FROM TABLE1)
                THEN 'YES'
                ELSE 'NO'
                END;

db<>fiddle here

Sign up to request clarification or add additional context in comments.

Comments

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.