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 Unable to catalog a gdg dataset resid... Shovan JCL & VSAM 7 Fri Mar 24, 2017 2:24 pm
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm
No new posts To display values of multiple rows in... vinu78 DB2 2 Thu Mar 09, 2017 1:20 pm
No new posts Calling procedure with multiple entri... steve-myers PL/I & Assembler 5 Fri Jan 27, 2017 3:33 pm
No new posts -913/-911 Deadlock during UPDATE stat... NoSleep319 DB2 5 Fri Nov 18, 2016 12:37 am


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