select p.*,
(select z.plik from zdjecia z where z.id_album=p.id_album and tresc = 0 order by z.photo_order asc limit 1) as plik
from produkty p
where p.publikacja = '1' and (p.id_producent = '71') and p.publikacja = '1' group by p.id_produkt order by p.nowosc desc, p.nazwa asc limit 0,12