Skip to content
Advertisement

SQL: Select all rows that are in range of 2 kilometres

Assuming I have the following PostgresSQL table locations name/longitude/latitude:

How can I select the rows that are in a radius of (for example) 10 kilometers from a starting point longitude 13.99999999999 and latitude 12.99999999999?

I accept any answer that gives me a concrete SQL statement.

Advertisement

Answer

Thanks guys. I found this stored procedure on some website (forgot the link). It works really well implementing the Haversine formula:

With that stored procedure, I was able to build a SQL select:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement