SELECT * FROM `districts` d INNER JOIN cities c ON d.districts_id = c.district_id INNER JOIN announcements a ON a.city_id = c.id WHERE( ( d.`districts_id` NOT IN ('100000000' ) AND d.id_region='180' AND d.`id_raion_bati`!='0')) AND a.flag_activ='1' AND c.idregion='180' AND c.`flag_real_city`='1' AND c.district_id!='' GROUP BY d.id_raion_bati ORDER BY d.district ASC