Intermediate · Lesson 6 of 20

Unique Values with DISTINCT

DISTINCT removes duplicate values.

List all unique departments:

SELECT DISTINCT department_id
FROM employees;

Works with multiple columns too:

SELECT DISTINCT department_id, salary
FROM employees;

This finds unique combinations.

COUNT with DISTINCT:

SELECT COUNT(DISTINCT department_id)
FROM employees;
Check your understanding

List all unique department IDs (no duplicates).

Examples run on the employees sample database. Open any of them in the playground to experiment.