The SQL SELECT DISTINCT
statement selects unique rows from a database table. For example,
SELECT DISTINCT country
FROM Customers;
Here, the SQL command selects unique countries from the Customers table.

Let's see another example.
SELECT DISTINCT country, first_name
FROM Customers;
Here, the SQL command selects rows if the combination of country and first_name is unique.

DISTINCT with COUNT
If we need to count the number of unique rows, we can use the COUNT()
function with DISTINCT
.
SELECT COUNT(DISTINCT country)
FROM Customers;
Here, the SQL command returns the count of unique countries.

To learn more, visit SQL COUNT().
More SQL DISTINCT Examples
Let's take a look at an example,
-- with distinct
SELECT DISTINCT country
FROM Customers;
-- with group by
SELECT country
FROM Customers
GROUP BY country;
Here, both of the SQL commands are similar and return unique countries from the Customers table.
To learn more, visit SQL GROUP BY.
Let's take a look at an example,
SELECT DISTINCT age
FROM Customers
ORDER BY age DESC;
Here, the SQL command selects unique ages and orders them in descending order from the Customers table.
To learn more, visit SQL ORDER BY.