Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Left join in update statement

user9216096Sep 4 2019 — edited Sep 4 2019

Hi,

I am trying to update by left joining the tables as below. when the data matches update the tbl2 value to tbl1, else update the value in tbl1 to 0. Can you let me know how to achieve this in Oracle 12g.

create table tbl1 (id int,sku int);
create table tbl2 (id int,sku int);

insert into tbl1 values(1,5);
insert into tbl1 values(2,10);
insert into tbl1 values(3,15);
insert into tbl1 values(4,20);

insert into tbl2 values(1,55);
insert into tbl2 values(3,11);

update tbl1 left join tbl2 on tbl1.id=tbl2.id set tbl1.sku = coalesce(tbl2.sku,0);

This post has been answered by Frank Kulash on Sep 4 2019
Jump to Answer
Comments
Post Details
Added on Sep 4 2019
8 comments
4,952 views