SELECT * from deal where site_id = 'swoogy.com' and deal_start <= 1337486400 and deal_end >= 1337486400 and featured = 'N' and (SELECT COALESCE( SUM(quant) , 0 ) FROM purchases where deal.id = deal_id) < deal_max order by RAND()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 '' at line 1