If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Left join

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-07-09, 21:16
joyjyothi joyjyothi is offline
Registered User
 
Join Date: Oct 2009
Posts: 1
Post Left join

Hello All,

I have two tables, Names of the tables are T1, T2. Both tables having Cus_iD, Plan. I need to retrieve a CUS,PL from T1, where Cus should have 2 or more plans and The same customer shold have atleast one of plan of T1, other plan sholdn't in T2.

I never used left or righter joins, but i am very comfortable with inner, Subseect, Exists and other functions,

I am having difficulty to execute my query, i am not getting expected results.


Please see the data below

T1 ( Should have Altest 2 plans)

CUS_ID Plan
111 ST
111 CT

T2

Cus_id Plan ( Should have 1 plan, the plan sholud be in T1)
111 ST

My result should be like

CUS ID, Plan
111 CT


My Query is

select CUs, PL
FROm T1,

Where date = 2009
and option = y
St_dt < end_dt
and Pl not in ( select Pl from T2
where
a.cus id = b.cus id
and a.pl = b.pl)

Please help me thank you
Reply With Quote
  #2 (permalink)  
Old 10-07-09, 22:34
DB2Plus DB2Plus is offline
Registered User
 
Join Date: Jul 2009
Posts: 150
I see you are one team !

Kara
Reply With Quote
  #3 (permalink)  
Old 10-08-09, 02:27
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Why do you think you need LEFT OUTER JOINS? You can join T1 with itself using CUS_ID as join predicate. Then you have for each CUS every combination and can check that one plan in the joined row exists in T2 and the other doesn't.

Since this smells like an exercise, you can figure out the details by yourself. With the above description, it should be straight-forward.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On