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 ') AND on_site = '1' AND p.price > 0 GROUP BY p.productid' at line 4