sql question #5

4

Click here to load reader

Upload: kai-liu

Post on 23-Jun-2015

280 views

Category:

Technology


0 download

DESCRIPTION

Update statement using inner join

TRANSCRIPT

Page 1: Sql Question #5

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

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

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

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)