SELECT ((ACOS(SIN($lat * PI() / 180) * SIN(lat * PI() / 180)
+ COS($lat * PI() / 180) * COS(lat * PI() / 180) * COS(($lon – lon) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS `distance`
FROM `members`
HAVING `distance`<=’10′
ORDER BY `distance` ASC
Got from the link http://zcentric.com/2010/03/11/calculate-distance-in-mysql-with-latitude-and-longitude/
It's for MySQL but you can adapt the code for any desired DB.