I would like to know if there is a way to query the nearest N neighbors from a spatial data column by dropping duplicates.
For example, my query looks like this:
SELECT TOP (@N) Point.STDistance(@Point) AS Distance
FROM MyTable
WHERE Point.STDistance(@Point) IS NOT NULL
ORDER BY Distance;
This is very effective, but my results are:
Distance
3906,81969203873
3906,81969203873
5321,62614141754
5756,28719382942
I tried to put a DISTINCT clause, but then it does not use the spatial index.
Any ideas?
thank
source
share