SELECT user2.*,
SQRT(POW(69.1 * (user1.latitude::float - user2.latitude::float), 2) +
POW(69.1 * (user2.longtitude::float - user1.longitude::float) * COS(user1.latitude::float / 57.3), 2)
) distanse
FROM users user1, users user2
WHERE user1.user_id=@p_user_id
ORDER BY distanse
LIMIT 10
UPD можно сократить запрос до одной таблицы:
SELECT users.*,
SQRT(POW(69.1 * (@p_user_latitude::float - users.latitude::float), 2) +
POW(69.1 * (users.longtitude::float - @p_user_longitude::float) * COS(@p_user_latitude::float / 57.3), 2)
) distanse
FROM users
ORDER BY distanse
LIMIT 10