SQL-2, left outer joins auf dieselbe Tabelle

Mache ich 2 joins auf die gleiche Tabelle und ich möchte die folgenden Ergebnisse:

chnl_ptnr_key type1_ky type2_ky
------------- -------- --------
1             1        null
1             2        null
1             null     3
1             null     4

Sondern ich bin immer

chnl_ptnr_key type1_ky type2_ky
------------- -------- --------
1             1        3
1             2        3
1             2        3
1             2        4

Meine Abfrage ist:

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'

Kann mir jemand helfen, dies zu ändern, Abfrage, so bekomme ich null in type1_ky und type2_ky wo die Zeile zurückgegeben wird, von der anderen beitreten?
Ich brauche dieses format, weil ich bin versucht, es für ein iBATIS Karte.

Vielen Dank

was ist Ihr schema für chnl_ptnr und chnl_ptnr_oos_map?
Sehr kryptische Namen und nicht die Bereitstellung der Daten der Tabellen.

InformationsquelleAutor ender | 2011-07-14

Schreibe einen Kommentar