Hallo,
Ich habe folgendes Problem.
Ich habe eine Table die etwa so aussieht:
table1:
Id | data1 | data2
------------------
01 | a | b
02 | c | d
03 | e | f
Ich will einen Join mit einer Table die etwa folgendermaßen aussieht:
table2:
Id | type | data3
------------------
01 | 2 | z
01 | 25 | yy
02 | 29 | x
03 | 5 | u
03 | 22 | v
03 | 25 | xx
Der Join soll über einen Match bei der "Id" stattfinden.
Ich will jedoch nur die Matches mit type 25.
Problem:
Vom type "25" gibt es jedoch entweder eine Zeile zu einer "Id", oder keine.
Ich will jedoch immer ein Match mit jeder Id aus table1.
Das bekomme ich:
table1+table2:
Id | data1 | data2 | type | data3
---------------------------------
01 | a | b | 25 | yy
03 | e | f | 25 | xx
Das will ich:
table1+table2:
Id | data1 | data2 | type | data3
---------------------------------
01 | a | b | 25 | yy
02 | c | d | 25 | unknown
03 | e | f | 25 | xx
So sieht mein SQL-Statement im Prinzip aktuell aus:
SELECT t1.Id, t1.data1, t1.data2, t2.type, t2.data3
FROM table1 as t1
LEFT JOIN table2 AS t2 ON t1.Id=t2.Id
WHERE t2.type=25
Was kann man da machen?
Ich habe folgendes Problem.
Ich habe eine Table die etwa so aussieht:
table1:
Id | data1 | data2
------------------
01 | a | b
02 | c | d
03 | e | f
Ich will einen Join mit einer Table die etwa folgendermaßen aussieht:
table2:
Id | type | data3
------------------
01 | 2 | z
01 | 25 | yy
02 | 29 | x
03 | 5 | u
03 | 22 | v
03 | 25 | xx
Der Join soll über einen Match bei der "Id" stattfinden.
Ich will jedoch nur die Matches mit type 25.
Problem:
Vom type "25" gibt es jedoch entweder eine Zeile zu einer "Id", oder keine.
Ich will jedoch immer ein Match mit jeder Id aus table1.
Das bekomme ich:
table1+table2:
Id | data1 | data2 | type | data3
---------------------------------
01 | a | b | 25 | yy
03 | e | f | 25 | xx
Das will ich:
table1+table2:
Id | data1 | data2 | type | data3
---------------------------------
01 | a | b | 25 | yy
02 | c | d | 25 | unknown
03 | e | f | 25 | xx
So sieht mein SQL-Statement im Prinzip aktuell aus:
SELECT t1.Id, t1.data1, t1.data2, t2.type, t2.data3
FROM table1 as t1
LEFT JOIN table2 AS t2 ON t1.Id=t2.Id
WHERE t2.type=25
Was kann man da machen?
Kommentar