Skip to content

Random notes about SQL ( mostly MySQL)

How to get different (unique) results

SELECT DISTINCT column-name
  FROM table-name

How to count different (unique) results

SELECT COUNT (DISTINCT column-name)
  FROM table-name

How to display different (unique) in alphabetical order

1
2
3
SELECT DISTINCT Country
  FROM Supplier
ORDER BY COUNTRY

How to find the difference between unique values and all values

SELECT (COUNT(CITY) - COUNT(DISTINCT CITY)) FROM STATION;

some reference