Distance
DISTANCE(g1 Geometry, g2 Geometry)
Alias: ST_DISTANCE
Returns the shortest distance between g1 and g2.
Result type: float
Examples:
Calculate the distance between two points:
SELECT DISTANCE(POINTFROMTEXT('POINT (-1 -1)'), POINTFROMTEXT('POINT (4 4)')) AS distance;
-----------
distance
-----------
7.071
-----------
g1 and g2 are points:
SELECT DISTANCE(POINTFROMTEXT('POINT(1 0)'), POINTFROMTEXT('POINT(1 5)'));
-----------
col1
-----------
5.000
-----------
g1 and g2 are triangles:
SELECT DISTANCE(POLYFROMTEXT('POLYGON((0 0, 1 2, 2 0, 0 0))'), POLYFROMTEXT('POLYGON((3 0, 3 2, 5 0, 3 0))'));
-----------
col1
-----------
1.000
-----------