bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL Tutorial
SQL•SQL Tutorial

SQL SELECT DISTINCT Statement

Concept visual

SQL SELECT DISTINCT Statement

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

The SQL SELECT DISTINCT Statement

The SELECT DISTINCT

statement is used to return only distinct
(unique) values.

Formula

In a table, a column may contain several duplicate values - and sometimes you want to list only the unique values.

Example

Select all the distinct (unique) countries from the "Customers" table:

SELECT DISTINCT Country FROM Customers;

SELECT DISTINCT Syntax

Select Distinct

column1, column2, ...

From

table_name

;

Demo Database

Below is a selection from the

Customers table used in the examples:

CustomerID

CustomerName

ContactName

Address

City

PostalCode

Country

Alfreds Futterkiste

Maria Anders

Obere Str. 57

Berlin

12209

Germany

Ana Trujillo Emparedados y helados

Ana Trujillo

Avda. de la Constitución 2222 México D.F. 05021

Mexico

Antonio Moreno Taquería

Antonio Moreno

Mataderos 2312

México D.F. 05023

Previous

SQL SELECT Statement

Next

SQL WHERE Clause