Hay i want to find the distance (in miles) between 2 locations using lat and long values, and check if they are within a 10 mile radius of each other.
When a user lo
Before your query, calculate the maximum and minimum latitude and longitude of your ten-mile circle. This will give you four numbers so the first part of your where clause will exclude any rows which fall outside of an approximate 10 mile-each way box.
Then the complicated real distance where clause checks only the ones inside the square, to see if they're also inside the circle.
Read your DBMS's docs to see whether lazy evaluation will apply or if you will need to arrange it as
SELECT *
FROM (SELECT *
FROM table
WHERE (simple rough box clause)
)
WHERE (complex clause)
instead of the usual
SELECT * FROM table WHERE (simple clause) AND (complex clause)