mySQL changing output unit of ST_Distance function I'm trying to get a result in nautical miles between two lon/lat saved in a point data type field in mySQL. However, the result seems to be not in any unit I'm familiar with (maybe degrees). How can I convert to my preferred unit?. My query as follows...

select t1.id, t2.id, ST_Distance(t1.test,t2.test) as DistanceApart from table1
t1 join table2 t2 on (ST_Distance(t1.test,t2.test) &lt;= 10)
Update Oct, 2018

Hello everyone,

If someone is still landing here wondering for an answer. I have found one. My scope was to get all cities under 50 miles radius of a city selected by the user.

In the database, I have longitude and latitude column of all the cities.

What I did, is that I made a new column loc of "Point" datatype to store the combination of longitude and latitude of each city.

Then lets say user has chosen a city with some $latitude and $longitude, so I get all nearby cities (within 100 miles) as:

st_distance(POINT( '.floatval($longitude).', '.floatval($latitude).' ) , loc) &lt;= 1.448


Putting this in you WHERE statement of MySQL query will give you all cities under 50 miles radius of that center city.

The formula I found to convert miles in angle is simple:

1 miles = 1/69.0585729 degree
Hence,
50 miles = 50/69.0585729 degree = 0.724 degree and 100 miles = 100/69.0585729 degree = 1.448 degree

If you need to have it in km, the formula goes like this:

1 degree = 111.139 km

Now you can convert km into degrees as well so that you can compare it with the output of st_distance() MySQL function

Please bear in mind that it might exclude some cities as mentioned by Rick in the comments. If you really want to go in depth of it, her eis the link posted by Rick James in the comment section, maybe this can help you out:

http://mysql.rjweb.org/doc.php/latlng

I hope it helps