You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Polo' AND enabled='1' AND in_stock>0 GROUP BY categoryID' at line 1 SQL query : SELECT categoryID,count(categoryID) as products_count FROM SS_products WHERE brand='Marc O'Polo' AND enabled='1' AND in_stock>0 GROUP BY categoryID