SELECT (SELECT count(id) FROM comments WHERE bankregnum=r.bnkregnum AND approve=1) count_comm , (SELECT cntbr FROM banks_in_city_rus WHERE regnum = r.bnkregnum AND city = "Красная Пахра" ) count_offices , r.* FROM (SELECT c.*, b.logo banklogo, b.name bankname, b.regnum regnum_common FROM crapp_rus c LEFT JOIN banks_rus b ON c.bnkregnum=b.regnum WHERE c.activ=1 AND EXISTS (SELECT 1 FROM cityadv_rus WHERE advid=c.id AND (cityname="*" or cityname="Красная Пахра")) ORDER BY LOWER(advname) LIKE '%налич%' DESC, priority ) r