sql question #5
DESCRIPTION
Update statement using inner joinTRANSCRIPT
![Page 1: Sql Question #5](https://reader038.vdocuments.us/reader038/viewer/2022100602/5589247ad8b42af7048b46ab/html5/thumbnails/1.jpg)
SQL Problem #5
Update statement using inner join
I have two tables TBUSERDTL TL and
SEQUENCENOUPDATE SU. I need to update the
TL.sequence_nu to the SU.sequence_nu. The
TL.eid is currently same as SU.eid so I am joining
on this column.
![Page 2: Sql Question #5](https://reader038.vdocuments.us/reader038/viewer/2022100602/5589247ad8b42af7048b46ab/html5/thumbnails/2.jpg)
The following update statement works fine in SQL Server:
UPDATE TBUSERDTL TL
SET SEQUENCE= SU.SEQUENCE_NU
FROM TABLE TBUSERDTL
INNER JOIN SEQUENCENOUPDATE SU
ON EID = SU.EID
THIS WILL NOT WORK IN ORACLE.
![Page 3: Sql Question #5](https://reader038.vdocuments.us/reader038/viewer/2022100602/5589247ad8b42af7048b46ab/html5/thumbnails/3.jpg)
How do I rewrite in Oracle
Solution 1:
update tbuserdtl
set sequence_nu =(select sequence_nu
from sequencenoupdate su
where tbuserdtl.eid = su.eid)
where eid in (select eid from sequencenoupdate)
Tbuserdtl and Sequencenoupdate. Updating sequence no
in detail table from the sequencenoupdate table where eid
matched.
![Page 4: Sql Question #5](https://reader038.vdocuments.us/reader038/viewer/2022100602/5589247ad8b42af7048b46ab/html5/thumbnails/4.jpg)
Improve Performance
Solution 2:
update tbuserdtl tl
set sequence_nu =(select su.sequence_nu
from sequencenoupdate su
where tbuserdtl.eid = su.eid)
where exists (select *
from sequencenoupdate su
where su.eid = tl.eid)