Beginner

393. DISTINCT

Learn how to return unique values and remove duplicate result rows.

📘 Lesson 393 of 728 ⏱ 8 min 🎯 Beginner

DISTINCT removes duplicate rows from the query result based on the selected columns.

Duplicate results can make reports confusing and can lead to incorrect interpretations when the requirement is to view unique values.

Find all unique departments in the Employees table.

SQL
SELECT DISTINCT
    Department
FROM Employees;

DISTINCT is useful for unique customer lists, department lists, product categories, locations, and exploratory data analysis.

  • DISTINCT removes duplicate result rows.
  • It applies to the selected columns.
  • Multiple columns can be used with DISTINCT.
  • DISTINCT does not permanently remove data.
  • It is useful for finding unique values.
What does DISTINCT do?

DISTINCT removes duplicate rows from the query result.

Does DISTINCT delete duplicate records from a table?

No. DISTINCT only removes duplicates from the query result and does not change the underlying table.

Have you finished this lesson?

Introduction to SQL – All Lessons