Hi marque,
Are your values always integers for longitude and latitude? Do you have a specified range for which you want to return results, i.e within 5 degree radius?
If both are true, this might(?) be a way to do this:
Create another table called range with 2 columns with values like this: populate it with every radius range combination: below shows 5 degree radius range:
longituderange latituderange
1 1
1 2
1 3
1 4
1 5
2 1
2 2
2 3
2 4
2 5
3 1
3 2
3 3
3 4
3 5
4 1
4 2
4 3
4 4
4 5
5 1
5 2
5 3
5 4
5 5
Here's my idea:
I'm thinking you can do a cartesian join with no where clause between your survey table and the range table (to get every combination of qualifying location)
Then do a join between the cartesian product against the location table to get a match.
Then you can do a ORDER BY on your results.
Here is the final query that I used, it is sligtly rearrange from how it is described above, but it seem to give the right results.
SELECT locations.longitude, locations.latitude, locations.place,
survey.longitude AS survey_longitude, survey.latitude AS survey_latitude
FROM survey, range, locations
WHERE
longituderange=abs(survey.longitude-locations.longitude) And latituderange=abs(survey.latitude-locations.latitude)
ORDER BY survey.longitude, survey.latitude,
abs(survey.longitude-locations.longitude), abs(survey.latitude-locations.latitude)
If you want to send me an email to bubblocity@yahoo.com, I'll send you the ACCESS database where I tested this.
If you have a different solution, do you mind posting it, I'm very curious about this...
Thanks.