The DISTINCT keyword returns only unique rows from the selected columns. Duplicate combinations of the selected column values are removed from the result.
Business data often contains repeated values, and analysts frequently need a unique list of departments, cities, customers, or categories.
Find the unique departments available in the Employees table.
SELECT DISTINCT
Department
FROM Employees;
DISTINCT is useful for creating unique lists, identifying categories, checking data quality, and preparing analysis.
- DISTINCT removes duplicate result rows.
- It applies to the selected columns.
- Multiple columns are evaluated together.
- It can be useful for data exploration.
- DISTINCT does not remove records from the table.
What does DISTINCT do?
DISTINCT returns only unique combinations of the selected columns.
Does DISTINCT delete duplicate data?
No. DISTINCT only removes duplicates from the query result; it does not modify the stored table.