IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

to update the column value of one table if matches


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 110
Location: india

PostPosted: Mon Jan 31, 2011 5:07 pm
Reply with quote

Hi, Here is the details. I want to resolve this thru an query.

I have 2 tables :

table a-- emp barcode
123 555
124 666
table b-- emp1 barcode1
123 999
124 888

If the column emp = emp1 for the 1st row, then update the barcode with the barcode1. for exp:

The updated table for the 1st row will be as per below.
table a-- emp barcode
123 999
124 666
table b-- emp1 barcode1
123 999
124 888

like that it will continue o update whenever it matches the emp with emp1.
Thanks in advance.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Jan 31, 2011 6:49 pm
Reply with quote

what are the indexes for the two tables?

can there be duplicates in table 1 for emp a?
i.e.:
Code:

emp    barcode
123     12344556
123     12344555


same applies to table b.

if there is only one row per emp in both tables,
why not
Code:

UPDATE TABA A
SET BARCODE = (SELECT BARCODE
                 FROM TABB B
                WHERE A.EMPLNO = B.EMPLNO)
WHERE A.EMPLNO IN (SELECT EMPLNO
                   FROM TABB )
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Mon Jan 31, 2011 6:55 pm
Reply with quote

or
Code:

UPDATE TABA A
SET BARCODE = (SELECT BARCODE
                 FROM TABB B
                WHERE A.EMPLNO = B.EMPLNO)
WHERE exists ( select EMPLNO
                   FROM TABB B where A.EMPLNO = B.EMPLNO)

same thing, different performance. Which one is the best depends on several things. Just try them both.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts How to load to DB2 with column level ... DB2 6
No new posts RC query -Time column CA Products 3
No new posts Multiple table unload using INZUTILB DB2 2
Search our Forums:

Back to Top