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

Update with multiple Joins


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Grouping by multiple headers DFSORT/ICETOOL 7
No new posts How to append a PS file into multiple... JCL & VSAM 3
Search our Forums:

Back to Top