You have a logical operation in order by, not in arithmetic. Try the following:
SELECT *
FROM mystore_table
WHERE `latitude` >=(51.5263472 * .9) AND `longitude` <=(-0.3830181 * 1.1)
ORDER BY abs(latitude - 51.5263472) + abs(longitude - -0.3830181)
limit 1;
ANDin the original version it will generate a logical value, either 0, or 1- and this will only 1be when the values match exactly with the last decimal point. Not very interesting.
There are many reasons why this is not the closest distance, but it can be close enough for your purposes. Here are a few reasons:
- Euclidean distance would occupy a square of differences
- The distance between two latitudes depends on longitude (from about 70 miles at the equator to 0 at the poles).
source
share