</>
Skip to content
SQL lessons (5/54)

SQL — Select Distinct

Basic DISTINCT

SELECT DISTINCT department
FROM employees;

Multiple columns

SELECT DISTINCT department, status
FROM employees;

COUNT with DISTINCT

SELECT COUNT(DISTINCT department) AS dept_count
FROM employees;

DISTINCT with ORDER BY

SELECT DISTINCT city
FROM customers
ORDER BY city;

DISTINCT in subquery

SELECT * FROM employees
WHERE department IN (
  SELECT DISTINCT department FROM employees WHERE salary > 50000
);

Mini Practice

Write SQL code that:

  1. Selects distinct values from a column
  2. Uses DISTINCT with multiple columns
  3. Counts distinct values
  4. Uses DISTINCT in a subquery

Up Next

In the next lesson, you'll learn about Having — filtering grouped data.

Related Topics

Frequently Asked Questions about Select Distinct

What is Select Distinct in SQL?

Select Distinct is a fundamental concept in SQL. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Select Distinct?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Select Distinct.

Why is Select Distinct important in SQL?

Select Distinct is essential for SQL development. Understanding this concept will help you write better code and solve real-world problems more effectively.