I’ve 2 tables, one with all my journal lines (table name: BoekstukRegels) and one with all journal descriptions (table name: balansen).
This works fine:
SELECT SUM(BoekRegelBedrag) AS TOTAL, BoekRegelGrootboekNr, BoekRegelPeriode
FROM BoekstukRegels
WHERE BoekregelUserId = 45 AND BoekRegelPeriode LIKE '2012%'
GROUP BY BoekRegelGrootboekNr
But the problem is I dont get the description. So I tried this:
SELECT SUM(BoekRegelBedrag) as total, BoekRegelPeriode, BoekRegelGrootboekNr, BaOmschrijving, BaSoort
FROM BoekstukRegels
LEFT JOIN balansen ON BoekRegelGrootboekNr = BaGbNumber
WHERE BoekregelUserId = 45 AND BoekRegelPeriode LIKE '2012%' AND BaSoort = 2
GROUP BY BoekRegelGrootboekNr
This gets me the description so that worked fine but the problem is that the totals dont match. I know what the problem is and that is because there are duplicates in the table balansen.
So in one way or another the table balansen needs a group by also but i cant get it working so i hope someone else can help me further.
Thanks in advance!
Do you know how to do the necessary group by on the other table to get the results you want? If so, then you can do something like this: