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 'polo' AND enabled='1' GROUP BY categoryID' at line 1 SQL query : SELECT categoryID,count(categoryID) as products_count FROM A_products WHERE brand='marc o'polo' AND enabled='1' GROUP BY categoryID