SELECT `registrationid` as `schoolid`, `LName` as `schoolname`, `address`, `city`, `state`, `educationboard`, `profiletype`, `gender`, `schoolcategory`, `localityarea`, (select count(*) from tblreviews where tblreviews.sourceid = tblregistration.registrationid) as reviewcount, (select avg(rating) from tblreviews where tblreviews.sourceid = tblregistration.registrationid) as rating, (select count(*) from tblschoolaccount where tblschoolaccount.schoolid = RegistrationId) as isclaimed, (select objectid from tblcompareobject where tblcompareobject.objectid=tblregistration.RegistrationId AND isdelete = 0 AND tblcompareobject.usersession= '284gskpvr03dpho13rlmg5ui3gj3gisq' ) as cmpid, (select count(*) from tblcompareobject where tblcompareobject.objectid=tblregistration.RegistrationId) as comparecount, (select count(*) FROM `tblschoolviews` where tblschoolviews.schoolid = tblregistration.RegistrationId) as viewcount, (((ACOS(SIN(0 * PI() / 180) * SIN(latitude * PI() / 180) + COS(0 * PI() / 180) * COS(latitude * PI() / 180) * COS((0 - longitude) * PI() / 180)) * 180 / PI()) * 60 * 1.1515 * 1.609344)) as distance FROM `tblregistration` WHERE `city` = 'Kanpur' HAVING `distance` <= 3 ORDER BY `distance` desc LIMIT 10