For example, say I have a table:
Business(BusinessID, Lattitude, Longitude)
All are indexed of course. Also there are 1 million records
Say I want to find businesses closest to 106,5, for example, how would I do so?
If I do
SELECT * FROM Business WHERE (Some formula to compute distance here) < 2000
for example, or if I do
SELECT * FROM Business TOP 20
In theory the computer will have to compute distance for all biz while in practice only those with lattitude and longitude within a certain range that should be computed.
So how can I do what I want in PhP, or SQL, for example?
I am grateful with the answer so far. I am using mysql and they do not have anything more efficient than the obvious solution. MySQL spatial do not have compute distance function either.