Ad space (banner)
🗄️SQL Lessons
Lesson 18 / 50

Removing Duplicates with DISTINCT

This lesson covers removing duplicate rows with DISTINCT, so you can list only the unique values in a column. It's for anyone searching "SQL DISTINCT tutorial."

SELECT DISTINCT column collapses duplicate values in the result down to one appearance each — handy when you want a "list of classes, with no repeats."

The example runs SELECT DISTINCT class_id FROM students;, and no matter how many students share a class, each class ID appears only once in the result — check that a class with multiple students still only shows up a single time.

A common early mistake is misjudging how DISTINCT behaves across multiple columns — specify more than one, and uniqueness is judged on the whole combination, not each column separately. Confirming "what values actually exist" before you dive into GROUP BY or WHERE conditions is a habit that makes the rest of a query much easier to design correctly.

SQL
OUTPUT

💡 The SQL engine may take a few seconds to load the first time you run code.

Ad space (banner)
Ad space (in-article)