Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

to update the column value of one table if matches

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
maxsubrat

New User


Joined: 27 Feb 2008
Posts: 72
Location: india

PostPosted: Mon Jan 31, 2011 5:07 pm    Post subject: to update the column value of one table if matches
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    Post subject:
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: 1278
Location: Belgium

PostPosted: Mon Jan 31, 2011 6:55 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
No new posts -913/-911 Deadlock during UPDATE stat... NoSleep319 DB2 5 Fri Nov 18, 2016 12:37 am
No new posts How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm
No new posts Updating Cursor row withour using FOR... chandan.inst DB2 15 Tue Nov 08, 2016 11:17 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us