VAŠ EKSPERT ZA KUHINJU

Zatvori
SELECT t1.id, t1.primaran, t1.naziv, t1.mpcena, t1.ascase FROM (SELECT a.id,a.primaran,a.naziv,a.mpcena,1 as ascase FROM `artikli` a LEFT JOIN artikli a2 on a2.parent_id = a.id WHERE a.`id`!='0' AND a.parent_id IS NULL AND a.`naziv` LIKE '%PLEON%' AND a.`novo`!='on' AND a.`aktivan`='on' AND a.`mpcena`!='0.00' AND a.`prikaz_b2c`='on' || (a.`id`!='0' AND a2.`naziv` LIKE '%PLEON%' AND a2.`novo`!='on' AND a2.`aktivan`='on' AND a2.`mpcena`!='0.00' AND a2.`prikaz_b2c`='on') UNION SELECT a.id,a.primaran,a.naziv,a.mpcena,1 as ascase FROM `artikli` a WHERE a.`id`!='0' AND a.parent_id IS NULL AND a.`naziv` LIKE '%PLEON%' AND a.`novo`!='on' AND a.`aktivan`='on' AND a.`mpcena`!='0.00' AND a.`prikaz_b2c`='on' UNION SELECT a.id,a.primaran,a.naziv,MIN(a.mpcena) as mpcena,1 as ascase FROM artikli a INNER JOIN artikli a2 ON a2.id = a.parent_id WHERE a.`id`!='0' AND a.parent_id IS NOT NULL AND a.`naziv` LIKE '%PLEON%' AND a.`novo`!='on' AND a.`aktivan`='on' AND a.`mpcena`!='0.00' AND a.`prikaz_b2c`='on' GROUP BY a.parent_id ) t1 ORDER BY ascase ASC, `id` DESC