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
 
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 HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts Join records from 2 files with No Dup... Poha Eater DFSORT/ICETOOL 22 Sun Aug 27, 2017 10:35 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Reduce CPU Times for Join Sort santoshn SYNCSORT 12 Sat Jun 10, 2017 1:40 pm

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