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
 

 

Left outer join query

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

New User


Joined: 02 Aug 2007
Posts: 83
Location: Here

PostPosted: Mon Jan 07, 2013 4:52 pm    Post subject: Left outer join query
Reply with quote

Hi,

I have a query on the below tables.

Code:

Table A
----------
CL_ID      E_NM      REC_ID
123          AAA       03
123          BBB       56
123          CCC       78
134          DDD       90

Table B
-----------
CL_ID      E_NM      E_CODE
123          AAA         TT
123          BBB         XX
134          DDD         ZZ

The result query should be as below

I need to retreive only the results of CL_ID = 123

CL_ID      E_NM      REC_ID    E_CODE
123         AAA         03            TT
123         BBB         56            XX
123         CCC         78          ----



I tried to do a left outer join but it gave the results of CL_ID= 134 as well. i dont want that to happen. This is the query i used. please advice how i can modify it to the requirements.

Code:

select A.CL_ID, A.E_NM,A.REC_ID, B.E_CODE
from Table A left outer join Table B
on
A.E_NM = B.E_NM and
A.CL_ID = B.CL_ID and
A.CL_ID = 123
Back to top
View user's profile Send private message

chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 269
Location: Mumbai

PostPosted: Mon Jan 07, 2013 5:19 pm    Post subject:
Reply with quote

Hi,

Did you tried this?

Code:
Select A.CL_ID, A.E_NM,A.REC_ID, B.E_CODE
from Table A left outer join Table B
on
A.E_NM = B.E_NM and
A.CL_ID = B.CL_ID
WHERE A.CL_ID = 123


I would suggest to go through the manuals to check how joins work

Regards,
Chandan
Back to top
View user's profile Send private message
CJT

New User


Joined: 02 Aug 2007
Posts: 83
Location: Here

PostPosted: Tue Jan 08, 2013 11:23 am    Post subject:
Reply with quote

Hi Chandan,

thank you so much. This worked fine for me.
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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
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
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


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