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

Left outer join query


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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: 275
Location: Mumbai

PostPosted: Mon Jan 07, 2013 5:19 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts RC query -Time column CA Products 3
No new posts Shift left VB record without x00 endi... DFSORT/ICETOOL 11
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
Search our Forums:

Back to Top