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 '000 AND (p.price >= 500 AND p.price <= 1000000) AND (SELECT COUNT(pi.id) FROM pr' at line 1(No Description) sql: SELECT p.id,p.parent_id, o.price FROM products p, productoffers o WHERE p.id = o.product_id AND p.parent_id = 0 AND hidden = 0 AND offers > 0 AND p.salesrank <= 1,000 AND (p.price >= 500 AND p.price <= 1000000) AND (SELECT COUNT(pi.id) FROM productimages pi WHERE pi.product_id = p.id) > 1 AND o.id IN (SELECT x.id FROM productoffers x WHERE x.product_id = p.id HAVING MIN(x.price)) ORDER BY p.price DESC LIMIT 24