Lesson 8 Beginner Level
8 of 30 lessons

DISTINCT Keyword

Learn how to remove duplicate values from query results using DISTINCT. The DISTINCT keyword is essential for retrieving unique values from your data.

What is DISTINCT?

The DISTINCT keyword is used in a SELECT statement to remove duplicate rows from the result set. This ensures that only unique values are returned.

Syntax

SELECT DISTINCT column1
FROM table_name;

Examples

-- List all unique job titles
SELECT DISTINCT job_id
FROM employees;

-- Get all unique department IDs from employees
SELECT DISTINCT department_id
FROM employees;

If there are multiple rows with the same job_id, only one will appear in the result.

Practice Task

  • Write a query to get all unique hire dates from the employees table.
  • Use DISTINCT with multiple columns: job_id and department_id.
  • Try comparing output with and without DISTINCT.