SELECT Statements SQL Topic exerciseEasyVerified answerSQLite + PostgreSQL + MySQL + SQL Server live · 1 guided

SELECT DISTINCT

Return distinct department IDs from employees.

  • Distinct values

Exercise brief

Understand the request

People analytics specialist The dashboard filter needs the unique list of department IDs currently in use.

Show each unique department_id that appears in the employees table, with no duplicates. (There are 4 unique departments represented.)

Return

  • Return department_id only.

Constraints

  • Remove duplicates with DISTINCT.

Data you will use

Review the relevant tables before deciding how to join, filter, or aggregate them.

employees

  • department_idINTEGER

Hints, when you need them

Open one clue at a time so you still do the reasoning.

Hint 1

DISTINCT removes duplicate result rows. It belongs immediately after SELECT.

Hint 2

Syntax: SELECT DISTINCT <column> FROM <table>;

Hint 3

Place DISTINCT immediately after SELECT and project only the department identifier.

Verified SQL answer

Attempt the problem first, then compare structure and reasoning—not just syntax.

Reveal solution and explanation
SELECT DISTINCT department_id FROM employees;

Why this works

DISTINCT collapses identical rows into one. Without it, this query would return 10 rows (one per employee) with department_id values repeating. With it, you get 4 rows — one for each department any employee belongs to.

Success check

Each department_id used by employees appears exactly once.

Expected result

Use this output to verify values, aliases, ordering, and row count.

department_id
10
20
30
40

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics:

Continue practicing

SQL Practice Online

Open the interactive workspace and practice across SQL topics.