I’m doing 2 joins on the same table and I want the following results:
chnl_ptnr_key type1_ky type2_ky
------------- -------- --------
1 1 null
1 2 null
1 null 3
1 null 4
But instead I’m getting
chnl_ptnr_key type1_ky type2_ky
------------- -------- --------
1 1 3
1 2 3
1 2 3
1 2 4
My query is:
SELECT cp.chnl_ptnr_ky, cpmap1.ky as type1_ky, cpmap2.ky as type2_ky
FROM chnl_ptnr cp
LEFT OUTER JOIN chnl_ptnr_oos_map cpmap1 on (cp.chnl_ptnr_ky = cpmap1.chnl_ptnr_ky and cpmap1.typ = 'TYPE1')
LEFT OUTER JOIN chnl_ptnr_oos_map cpmap2 on (cp.chnl_ptnr_ky = cpmap2.chnl_ptnr_ky and cpmap2.typ = 'TYPE2')
WHERE cp.chnl_ptnr_ky = '1111'
Can someone help me to change this query so I get nulls in type1_ky and type2_ky where the row is being returned from the other join?
I need this format because I’m attempting to use it for an iBATIS map.
Many thanks
In your example, the results of the first
LEFT JOINare (1,1) and (1,2). As there are no (1,NULL) records, there will be no (1,NULL,?) records after the nextLEFT JOIN.You probably need a UNION in there somewhere…