Selecting Distinct combinations.

SELECT COLUMN1,COLUMN2 
FROM TABLE_NAME 
GROUP BY COLUMN1,COLUMN2 -- This will fetch the unique combinations

-- During this kind of selection it is always better to give a where condition so that the results are filtered before grouping

Your Code:

SELECT Latitude, Longitude 
  FROM Coordinates
GROUP BY Latitude, Longitude  


its an old post. but I just came across it while looking for an anser for the same problem. The above answer didn't work for me, but I found another simple solution using CONCAT():

SELECT *
FROM Coordinates
GROUP BY CONCAT(Latitude, Longitude);

This will give you all the unique Latitude / Longitude combinations, without any limitations to the select part of the query.


I think it will be something about :

SELECT latitude, longitude 
FROM table_name t1 
INNER JOIN table_name t2 
WHERE t1.latitude <> t2.latitude OR t1.longitude <> t2.longitude

That is the SELF INNER JOIN.


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;

Tags:

Sql