mysql - SQL needed to get a subset of locations based on lat/long with a min/max distance constraint -
i have mysql table 500 location records has similar structure to:
id, name, lat, long
lat & long decimal (float) location values.
my need return random 100 record set minimum 200 meters , maximum 500 meters away each other. i'm familiar using great circle formula distance between 2 points. however, have no idea how write select statement compare locations against each other ensure distance requirements random 100 selected? thoughts or appreciated. tools mysql database solution needs written in mysql sql. thank in advance.
select * ( select p.latitude1 latitude1, p.longitude1 longitude1, p.latitude2 latitude2, p.longitude2 longitude2, (((acos(sin((latitude2*pi()/180)) * sin((latitude1*pi()/180))+cos((latitude2*pi()/180)) * cos((latitude1*pi()/180)) * cos(((longitude2- longitude1)* pi()/180))))*180/pi())*60*1.1515) distance places p ) distance > 200 , distance < 500 order rand() limit 100