I'm currently working with geo point with MySql 5.7. My currently request is :
SELECT pA.id as pa, pB.id as pb, ST_Distance(pA.geo, pB.geo) as distance
FROM point_A pA
JOIN point_B pB
ORDER BY pa, distance
Sample output :
+-------+-------+---------------------+
| pa | pb | distance |
+-------+-------+---------------------+
| 1 | 5535 | 0.23752813469351355 |
| 1 | 5536 | 0.8110224552241297 |
| 1 | 5533 | 0.8359718468573036 |
| 2 | 5536 | 0.8763100264270072 |
| 2 | 5536 | 0.0665454376162462 |
| 2 | 5533 | 1.0669544991122402 |
| 3 | 5533 | 0.2469039758259646 |
| 3 | 5536 | 0.329452951307464 |
| 3 | 5533 | 1.3593527448933072 |
I want only first occurence of each pa. I can't find a way to do this without using subrequest and a second time ST_Distance ( which has a cost in performance )
expected result :
+-------+-------+---------------------+
| pa | pb | distance |
+-------+-------+---------------------+
| 1 | 5535 | 0.23752813469351355 |
| 2 | 5536 | 0.8763100264270072 |
| 3 | 5533 | 0.2469039758259646 |
I already tried with group by and distinct but all my distance value are unique with couple pa, pb.