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, 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 = w.projekt WHERE p.pokaz IN (0,2) AND = w.projekt AND w.cena > 0 AND w.szerokosc >= 0 GROUP BY ORDER BY p.topign DESC, DESC, p.rodzajdomu LIMIT 0,