SELECT c.* FROM `inp_latest` d JOIN (SELECT a.*, b.`FID`,b.`img_url` FROM `inp_properties` a LEFT JOIN `inp_property_medias` b ON a.`id`=b.`property_id` AND b.`status`='1' AND b.`media_type`='1' WHERE a.`status`='1') c ON d.`property_id`=c.`id` ORDER BY d.`index`;