I'm working on an OpenSource and free database provided by IP2Location that lists tons of IP addresses from internet.
You can download it from here.
My main interest aren't IP addresses: I want to have 1 geographical coordinate for each city per country.
The query I have now returns me doubles:
WITH cte AS
(
-- Let's pass rows that have the same latitude and longitude
SELECT *, ROW_NUMBER() OVER (PARTITION BY latitude, longitude
ORDER BY latitude, longitude) AS rn
FROM ip2location_db11
-- Avoid rows without city name
where city_name != '-'
)
SELECT
-- These are the only columns I'm interested in from the whole ip2location_db11 database
ROW_NUMBER() OVER (ORDER BY country_code desc,city_name desc) as countdown_order,
latitude,longitude,city_name,country_code
FROM cte
-- Let's take the first row where latitude and longitude are the same
WHERE rn = 1
-- I want to order results by city name
order by countdown_order desc
Which is very annoying:
One row with one latitude and longitude per city will be fine: I just want to put a pin on a map