I have a query with a left join that is acting rather strange. It returns 1 row, though it should return 3 rows (that is what you get if i would leave out the left join and its columns). What is even more remarkable is that it returns 2 rows when changing Left to Inner join. I think i know a whole lot of SQL but this goes above my baseballcap (as we say in Holland).
Here is the query:
Here is the query:
Code:
SELECT DP.Omschrijving AS Omschrijving, 4 AS Niveau, IIf(Nz(DP.ProcesStapID,0)>0,(100*P.ProcesID + DP.ProcesStapID),P.ProcesID) AS ID, Sum(Nz(V.WaardeOchtend,0)) AS VolumeOchtend, Sum(Nz(V.WaardeMiddag,0)) AS VolumeMiddag, Sum(Nz(V.WaardeAvond,0)) AS VolumeAvond, Sum(Nz(V.WaardeNacht,0)) AS VolumeNacht
FROM ((Proces AS P INNER JOIN ProcesProductie AS DP ON DP.ProcesID = P.ProcesID) INNER JOIN SubSelectieVolume AS V ON V.ProcesCode = DP.ProcesCode AND V.ProcesStapID = DP.ProcesStapID)
LEFT JOIN SubSelectiePlanningProductie AS PL ON (PL.SorteerCentrumID = V.SorteerCentrumID AND PL.ProcesCode = V.ProcesCode AND PL.PeriodeID = V.PeriodeID AND PL.Datum = V.Datum AND PL.ProcesStapID = V.ProcesStapID)
GROUP BY V.SorteerCentrumID, DP.Omschrijving, P.ClusterID, P.ProcesID, P.SortPulldown, DP.ProcesStapID;