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 (select count(*) from galeria_zdjecie where galeria_id = g.id) > 0' at line 1
select count(*) from galeria g where g.galeria_kategoria_id = and (select count(*) from galeria_zdjecie where galeria_id = g.id) > 0