I have a database with lng and lat columns for each row. How can I make a SQL query that will return the rows in order of the distance? I will compare the lat and lng with external values. I will send the SQL query with PyMySQL using Python. If this isn't possible, I have the haversine formula written in Python, and I can calculate the distances like that, but I don't want to have to waste time looping through all the entries in the database, which is very big.
Sample Table:
long ============ lat
============================
1. -74 ============= 84
2. -87 ============= 75
What I expect to happen. I give a long, lat coordinate and it compares it to all the rows in the database, and it returns the rows in order of the closest to the farthest to the coordinate I provide.