Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting distinct combinations

Tags:

sql

I have a table which has 2 fields (latitude, longitude) and many other fields. I want to select the distinct combinations of latitude and longitude from this table.

What would be the query for that?

like image 641
Codevalley Avatar asked Jul 29 '11 08:07

Codevalley


1 Answers

Simply use the DISTINCT keyword:

SELECT DISTINCT Latitude, Longitude  FROM Coordinates; 

This will return values where the (Latitude, Longitude) combination is unique.

This example supposes that you do not need the other columns. If you do need them, i.e. the table has Latitude, Longitude, LocationName columns, you could either add LocationName to the distinct list, or use something along the lines of:

SELECT Latitude, Longitude, MIN(LocationName) FROM Coordinates GROUP BY Latitude, Longitude; 
like image 131
SWeko Avatar answered Sep 21 '22 07:09

SWeko