⚡ 180+ new openings posted today

SQL SELECT DISTINCT Statement

What is SELECT DISTINCT ?

Answer : The SQL SELECT DISTINCT statement is used to return only distinct(unique) records. There May be a situation when you have a multiple duplicate records in a table. While fetching such records, it makes more sense to fetch only those unique records instead of fetching duplicate records.

Syntax

SELECT DISTINCT column_name
FROM table_name;

Example

Suppose we have an Employees table:

Employee_IDEmployee_NameDepartment
101RahulIT
102PriyaHR
103AmitFinance
104JohnFinance

If we want to fetch the unique departments:

SELECT DISTINCT Department
FROM Employees;

Output

Department
IT
HR
Finance

Here, Finance appears twice in the table, but SELECT DISTINCT returns it only once.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top