select oferte.pret_brut, -- producatori.producator as producer, -- categorii.categorie as category, -- if(oferte.categorie=131,categorii.categorie,'') as category, categorii.categorie_id, categorii.categorie_seo, oferte.id as pid, -- foto.nume_foto fnume, foto.foto_id fid, oferte.rating/(if (oferte.votari>0,oferte.votari,1) ) as stele from oferte -- join producatori -- on oferte.producator=producatori.producator_id -- join categorii -- on oferte.categorie=categorii.categorie_id -- left join foto -- on oferte.id=foto.id left join (select * from asocieri_produse where categ_id is not null and categ_id >0 and categ_secundara=1) categsec on oferte.id=categsec.oferta_id -- left join categorii categorii2 -- on categsec.categ_id=categorii2.categorie_id where (oferte.categorie=131 or categsec.categ_id=131) AND (pret_brut >= and pret_brut <= ) AND 1=1 and pret_brut>0 and oferte.inactiv=0 and oferte.inactiv_liste=0 group by oferte.id order by pret_brut limit 0,12