2

I have 2 tables with Naam as primary key, the one table contains information on Naam (lumchartcentrumuser) and the other table contains information on presentations held by naam (lumchartecentrumonderwijs).

I want to use a bit more complex aggregation which counts the number of presentations grouped by Naam, using a where however i keep on getting errrors. Does anybody see what i am doing wrong :

SELECT lumchartcentrumuser.Naam,
       COUNT(lumchartecentrumonderwijs.ID) AS Getal
FROM lumchartecentrumonderwijs
WHERE lumchartcentrumuser.Type <> 3
 AND lumchartecentrumonderwijs.Categorie <> "
LEFT JOIN lumchartcentrumuser ON
lumchartecentrumonderwijs.Naam=lumchartcentrumuser.Naam 
GROUP BY Naam
Kirill Kin
  • 391
  • 1
  • 7
Mihaly
  • 303
  • 1
  • 3
  • 14

2 Answers2

2

The syntax is wrong. It should be like SELECT..FROM...JOIN...WHERE...GROUP BY

SELECT lumchartcentrumuser.Naam, COUNT(lumchartecentrumonderwijs.ID) AS Getal
FROM lumchartecentrumonderwijs 
LEFT JOIN lumchartcentrumuser 
ON lumchartecentrumonderwijs.Naam=lumchartcentrumuser.Naam 
WHERE lumchartcentrumuser.Type <> 3 AND 
      lumchartecentrumonderwijs.Categorie <> '' 
GROUP BY Naam
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
0

You need to move your WHERE statements below the JOIN statements. Something like this

SELECT lumchartcentrumuser.Naam, COUNT(lumchartecentrumonderwijs.ID) AS Getal
FROM lumchartecentrumonderwijs 
LEFT JOIN lumchartcentrumuser 
ON lumchartecentrumonderwijs.Naam = lumchartcentrumuser.Naam
WHERE lumchartcentrumuser.Type <> 3 AND lumchartecentrumonderwijs.Categorie <> ""
GROUP BY Naam

Also make sure you close your quotation marks (fixed above).

Jake Bathman
  • 1,268
  • 3
  • 18
  • 25