I am trying to retrieve the top 5 values in a certain column in a mysql database.
I have the following query:
SELECT `dep_aerodrome`,
Count(`dep_aerodrome`) AS `cnt`
FROM sectors
WHERE ( `group` = '".$_SESSION['GROUP']."'
AND ( $bases ) NOT IN dep_aerodrome )
GROUP BY `dep_aerodrome`
ORDER BY `cnt` DESC
LIMIT 5
The query contains a WHERE
clause and NOT IN
to not include airports that are registered as bases.
I am getting the following syntax error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'dep_aerodrome) GROUP BY dep_aerodrome
ORDER BY cnt
DESC LIMIT 5' at line 1
and I cannot figure out where it is coming from. Can anyone help out?