SQL SELECT DISTINCT Statement

The SQL SELECT DISTINCT Statement

The SELECT DISTINCT statement is used to return only distinct (different) values.

Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.

SELECT DISTINCT Syntax

SELECT DISTINCT column1, column2, ...
FROM table_name;

The following SQL statement selects only the DISTINCT values from the "Country" column in the "Customers" table:

SELECT

The following SQL statement selects all (and duplicate) values from the "Country" column in the "Customers" table»

SELECT Country FROM Customers;

Now, let us use the DISTINCT keyword with the above SELECT statement and see the result.

SELECT DISTINCT Examples

The following SQL statement selects only the DISTINCT values from the "Country" column in the "Customers" table:

SELECT COUNT(DISTINCT Country) FROM Customers;

The following SQL statement lists the number of different (distinct) customer countries:

SELECT COUNT(DISTINCT Country) FROM Customers;

Problems :

  1. Consider the below data from 'Order' table, write a SQL to fetch the unique regions.

  2. Write a SQL to find the list of Items sold.

Last updated