Shortest Distance in a Plane



@Mr.Bin Right. I mean the " (p1.x <= p2.x AND p1.y <=p2.y)
and (p1.x != p2.x or p1.y != p2.y)" part after "ON" for join clause. This will only return n*(n1)/2 points.

@xinyulrsm if p1 is (1, 0) and point p2 is (2, 1), then your algorithm won't be able to satisfy your join conditions.
Here is one that works, which doesn't have duplicate combinations:
SELECT
ROUND(SQRT(MIN((POW(p1.x  p2.x, 2) + POW(p1.y  p2.y, 2)))),2) AS shortest
FROM
point_2d p1
JOIN
point_2d p2 ON ((p1.x < p2.x) OR (p1.x = p2.x AND p1.y < p2.y))
AND (p1.x != p2.x OR p1.y != p2.y)