0% found this document useful (0 votes)
43 views2 pages

SQL SELECT DISTINCT Statement

The SELECT DISTINCT statement returns only distinct (different) values from a column. It is used when a column contains many duplicate values and you only want the unique values listed. The syntax includes the DISTINCT keyword followed by the column name(s) and the table name. An example selects the distinct city values from the Customers table to remove duplicate city entries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views2 pages

SQL SELECT DISTINCT Statement

The SELECT DISTINCT statement returns only distinct (different) values from a column. It is used when a column contains many duplicate values and you only want the unique values listed. The syntax includes the DISTINCT keyword followed by the column name(s) and the table name. An example selects the distinct city values from the Customers table to remove duplicate city entries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

SQL SELECT DISTINCT Statement

« Previous
Next Chapter »

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

The SQL SELECT DISTINCT Statement


In a table, a column may contain many duplicate values; and sometimes you only want to list
the different (distinct) values.

The DISTINCT keyword can be used to return only distinct (different) values.

SQL SELECT DISTINCT Syntax

SELECT DISTINCT column_name,column_name


FROM table_name;

Demo Database
In this tutorial we will use the well-known Northwind sample database.

Below is a selection from the "Customers" table:

CustomerID CustomerName ContactName Address City PostalCode Country


1 Alfreds
Maria Anders Obere Str. 57 Berlin 12209 Germany
Futterkiste
Ana Trujillo Avda. de la
México
2 Emparedados y Ana Trujillo Constitución 05021 Mexico
D.F.
helados 2222
Antonio Moreno Antonio Mataderos México
3 05023 Mexico
Taquería Moreno 2312 D.F.
4 120 Hanover
Around the Horn Thomas Hardy London WA1 1DP UK
Sq.
Berglunds Christina Berguvsvägen
5 Luleå S-958 22 Sweden
snabbköp Berglund 8

SELECT DISTINCT Example


The following SQL statement selects only the distinct values from the "City" columns from
the "Customers" table:

Example
SELECT DISTINCT City FROM Customers;

Try it yourself »

You might also like