SQL SELECT DISTINCT

The SELECT DISTINCT statement in SQL is used to retrieve only the unique values from a column (or a set of columns). It filters out duplicate rows from the query's results, giving you a list of distinct values.



SELECT DISTINCT: Definition and Usage

SELECT DISTINCT is very helpful when you need only a list of unique entries and don't want to see repeated values. This is commonly used to get a list of all available options for a particular column (such as distinct countries, product categories, or any other attribute where you're interested only in unique entries).

Syntax

Syntax

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

Example

Retrieving Unique Countries

This query selects only the unique country names from the 'Customers' table. (Assumes a 'Customers' table exists with a 'Country' column.)

Syntax

SELECT DISTINCT Country FROM Customers;
      
Output

Country
-------
(A list of unique country names from the Customers table will be displayed here.)
      

**Note:** The example output shows a general structure. The specific countries returned and their order will depend on the data present in your `Customers` table. If a country name is repeated in the `Customers` table, `SELECT DISTINCT` ensures that it will only appear once in the results.