;

SQL SELECT DISTINCT


In this Tutorial, we will learn how to SELECT DISTINCT records from the table using SQL.

SQL SELECT DISTINCT Statement

The SELECT DISTINCT Statement is used to eliminate all the duplicate records and fetch/retrieve only unique records from the table present in the database.

Syntax - SELECT DISTINCT Statement
SELECT DISTINCT column1, column2,...columnN
FROM tableName;

Example:

Let us consider this table "Employee" for records.

Table Name: Employee

ID EmpName City Country Gender Salary
1 Shankar Delhi India male 25000
2 Sourabh Delhi India male 30000
3 Ranvijay Mumbai India male 15000
4 Kapil Noida India male 25000
5 Shalini Jaipur India female 18000
6 Rakesh Faridabad India male 23000
7 Akshay Mumbai India male 21000
8 Sarah New York US female 76000
9 Rocky Noida India male 28000

Here are some examples of SELECT DISTINCT statement:

First, lets us see how to SELECT Statement returns the duplicate "City" Records from table "Employee"

Example
SELECT City FROM Employee;
Output
City
Delhi
Delhi
Mumbai
Noida
Jaipur
Faridabad
Mumbai
New York
Noida

Now, lets us see how to SELECT DISTINCT Statement returns the "City" Records from table "Employee"

Example - SELECT DISTINCT Statement
SELECT DISTINCT City 
FROM Employee;
Output
City
Delhi
Mumbai
Noida
Jaipur
Faridabad
New York