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 - SELECT p.*, MIN(w.szerokosc) as szer, w.vat as vat, w.cena, w.promo as promo, w.promo_cena as promo_cena FROM projekty p INNER JOIN (SELECT id,projekt,vat,cena,promo,promo_cena,szerokosc,garaz,dostepny,promocja_tylko_przelew FROM wersje ORDER BY (cena * (1+vat/100))) AS w ON p.id = w.projekt WHERE p.pokaz IN (0,2) AND p.id = w.projekt AND w.cena > 0 AND w.szerokosc >= 0 GROUP BY p.id ORDER BY p.topign DESC, p.top DESC, p.rodzajdomu LIMIT 0,