Part 12: Eliminating Duplicates with SELECT DISTINCT

Part 12 Technology Updated September 12, 2026

Part 12: Eliminating Duplicates with SELECT DISTINCT

The DISTINCT keyword removes duplicate rows from your query output.


1. Basic DISTINCT Syntax

-- Find all unique departments:
SELECT DISTINCT department FROM employees;

2. Multi-Column DISTINCT

When multiple columns are specified, DISTINCT applies to the combination of all selected columns:

SELECT DISTINCT department, job_title FROM employees;

This returns unique combinations of department and job title.


3. Performance Warning

DISTINCT requires the database engine to sort the entire result set or build a hash table in memory to identify duplicates. Do not use DISTINCT as a band-aid to mask bad join conditions!


Key Takeaways

  • DISTINCT filters out duplicate rows.
  • It applies to the entire set of selected columns, not just the first one.

In Part 13, we will master Filtering Records with the WHERE Clause!