SQL Problem mit Join

slay24

Lt. Junior Grade
Registriert
Aug. 2004
Beiträge
409
Hallo Ich habe ne Tabelle die enthält daten wobei es jeden Datensatz 3 mal gibt und sich nur in der Spalte "Tour" unterscheidet. Es gibt 3 Touren also enthält diese Spalte den Wert 1,2 oder 3.

Tabelle:
ChainStoreNo Tour ItemNo ItemDescription Quantity
12 1 1 NULL 2
12 2 1 NULL 3
12 3 1 NULL 4
14 1 2 NULL 2
14 2 2 NULL 3
14 3 2 NULL 4

Ich habe nun diesen JOIN geschrieben

SELECT a.chainstoreno, a.itemno, a.itemdescription, a.quantity as Tour1,b.quantity as Tour2
FROM [Cash Box Order Proposal] as a
INNER JOIN [Cash Box Order Proposal] AS b
ON a.itemno = b.itemno
where a.tour=1 and b.tour=2
ORDER BY a.itemno

Ergebnis:

ChainStoreNo ItemNo ItemDescription Tour1 Tour2
12 1 NULL 2 3
14 2 NULL 2 3

Nun wollte ich Tour 3 auch dazuholen und habe versucht es so zu machen

SELECT a.chainstoreno, a.itemno, a.itemdescription, a.quantity as Tour1,b.quantity as Tour2, c.quantity as Tour3
FROM [Cash Box Order Proposal] as a
INNER JOIN [Cash Box Order Proposal] AS b
ON a.itemno = b.itemno
INNER JOIN [Cash Box Order Proposal] AS c
ON a.itemno = b.itemno

where a.tour=1 and b.tour=2 and c.tour=3
ORDER BY a.itemno

aber das Ergbnis ist:

ChainStoreNo ItemNo ItemDescription Tour1 Tour2 Tour3
12 1 NULL 2 3 4
12 1 NULL 2 3 4
14 2 NULL 2 3 4
14 2 NULL 2 3 4

ich wollte aber:

ChainStoreNo ItemNo ItemDescription Tour1 Tour2 Tour3
12 1 NULL 2 3 4
14 2 NULL 2 3 4

geht das irgentwie? wie bekomme ich die doppelten zeilen raus
 
Zuletzt bearbeitet:
Code:
[COLOR=Red][COLOR=black]INNER JOIN [Cash Box Order Proposal] AS c[/COLOR]
    ON a.itemno = b.itemno[/COLOR]
Guck dir mal genau an, was da in rot steht. Dann müsste dir der Fehler eigentlich auffallen.
 
:S is ja peinlich scheiße danke *rotwerd*
 
Zurück
Oben