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
 

 

Update with multiple Joins

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

New User


Joined: 09 Apr 2008
Posts: 83
Location: Chennai

PostPosted: Tue May 19, 2009 8:52 am    Post subject: Update with multiple Joins
Reply with quote

I have the following requirements:
There are two tables UTT_EMPL_MGR and UTT_EMPL_ID.
The columns in the table UTT_EMPL_MGR are as follows:
EMPL_ID
MGR_EMPL_ID
REL_TYP_CD
REL_FINAL_CD

The columns in the table UTT_EMPL_MGR are as follows:
EMPL_NUM
MGR_EMPL_NUM
REL_TYP_CD
REL_FINAL_CD

The above two tables have the parent table as UTT_EMPL. The columns in the table UTT_EMPL are:
EMPL_ID
EMPL_NUM
EMPL_NAME
TERM_CD

For some Employees, the REL_FINAL_CD is not matching between the UTT_EMPL_MGR and UTT_EMPL_ID. If i have to update the REL_FINAL_CD
of all the erroneous records in the UTT_EMPL_ID with the REL_FINAL_CD of UTT_EMPL_MGR, then is there a way to write the Update query?

Thanks!!
Back to top
View user's profile Send private message

Prajesh_v_p

Active User


Joined: 24 May 2006
Posts: 133
Location: India

PostPosted: Tue May 19, 2009 1:46 pm    Post subject:
Reply with quote

Please check whether something like below will work for you(I hope the key match MGR.MGR_EMPL_ID = ID.EMPL_NUM is correct) :

UPDATE UTT_EMPL_ID ID
SET ID.REL_FINAL_CD = (
SELECT MGR.REL_FINAL_CD
FROM UTT_EMPL_MGR MGR
WHERE MGR.MGR_EMPL_ID = ID.EMPL_NUM )

WHER ID.REL_FINAL_CD NOT IN(
SELECT MG1.REL_FINAL_CD
FROM UTT_EMPL_MGR MG1
WHERE MG1.MGR_EMPL_ID = ID.EMPL_NUM );

I am not sure whether we can get rid of these two subqueries!
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 -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
No new posts Converting multiple VB files to FB fi... Viswanath Reddy JCL & VSAM 6 Mon Aug 08, 2016 11:49 pm
No new posts Execute multiple DB2 Load commands in... faizm DB2 4 Wed Aug 03, 2016 12:53 pm


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