select m.*, mp.* from members m inner join member_profile mp on m.memberId = mp.memberId where 1 and ((TO_DAYS(NOW())-TO_DAYS(mp.dob))/365) between 18 and 49 and mp.country = 221 and mp.isPublic = 'Yes' and mp.isActive = 'Yes' and m.is_active = 'y' order by mp.is_photo_there,m.memberId desc