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 '.price >= 2000AND o.price <= 1000000) OR p.parent_id IN (SELECT product_id FROM ' at line 2(No Description) sql: SELECT DISTINCT p.id FROM products p, productoffers o WHERE p.id IN (SELECT product_id FROM productoffersAND o.price >= 2000AND o.price <= 1000000) OR p.parent_id IN (SELECT product_id FROM productoffersAND o.price >= 2000AND o.price <= 1000000) LIMIT 6