Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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 Merging 2 records at multiple rows wi... Bijesh DFSORT/ICETOOL 2 Wed Dec 06, 2017 1:50 am
No new posts Formatting multiple records to a sing... Vignesh Sid SYNCSORT 3 Tue Nov 07, 2017 12:22 pm
No new posts Updating multiple counts in trailer!! Vignesh Sid SYNCSORT 4 Mon Nov 06, 2017 1:04 pm
No new posts Selecting a row from multiple tables! Vignesh Sid DB2 2 Thu Oct 26, 2017 6:09 pm
No new posts Update table without cursor Ron Klop DB2 3 Wed Oct 11, 2017 1:06 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us