SELECT IFNULL(vcena,cena) as cena, IFNULL(vsleva,sleva) as sleva, IFNULL(vdostupnost,dostupnost) as dostupnost, IFNULL(vdodani,dodani) as dodani, pro.nazev, pro.popis,, pro.id_kategorie, pro.obrazky, pro.akce, pro.novinka, pro.postovne, pro.u_dodavatele, pro.vyrobce, pro.zobrazit as zobrazit, pro.objednat as objednat FROM (SELECT v.cena_cz as vcena, v.sleva_cz as vsleva, v.dostupnost as vdostupnost, v.dodani as vdodani,, p.vyrobce, p.akce_cz as akce, p.novinka, p.postovne, p.obrazky, p.u_dodavatele, p.nazev_cz as nazev, p.popis_cz as popis, p.cena_cz as cena, p.sleva_cz as sleva, p.dostupnost, p.dodani, p.zobrazit_cz as zobrazit, p.objednat_cz as objednat, p.id_kategorie FROM atan_produkty as p LEFT OUTER JOIN atan_varianty as v ON = v.id_produkt WHERE IN (16291, 16003, 20387, 16001)) AND p.zobrazit_cz = '1' AND p.objednat_cz = '1' ORDER BY vdostupnost, CASE WHEN vdodani = '0000-00-00' THEN '2099-12-31' ELSE vdodani END, vsleva, vcena) as pro GROUP BY id LIMIT 1000
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 'AND p.zobrazit_cz = '1' AND p.objednat_cz = '1' ORDER BY vdostupnost, CASE WHEN ' at line 1