Back to SQL Notes
Topic #81

SQL SELECT DISTINCT

SELECT DISTINCT removes duplicate rows from the result — it keeps only unique combinations of the selected columns.

Syntax

SELECT DISTINCT column1, column2
FROM table_name;

Sample Table: employees

idnamedepartment
1AmanEngineering
2RiyaMarketing
3KaranEngineering
4NehaMarketing

Example

SELECT DISTINCT department
FROM employees;

Output:

department
Engineering
Marketing

Four rows collapse to two — one per unique department.

DISTINCT on Multiple Columns

SELECT DISTINCT department, salary
FROM employees;

This keeps a row only if the combination of department and salary is unique — not just the department alone. Easy to misread if you're used to DISTINCT on a single column.

Practical Use Case

Finding the list of distinct categories, cities, or statuses present in a table — e.g. "which departments actually have employees right now?" before building a filter dropdown in an app.

Common Mistakes

  • Using DISTINCT * on a wide table when only a couple of columns are actually relevant — this can be needlessly slow
  • Assuming DISTINCT removes duplicates per column independently — it deduplicates the whole row of selected columns together
  • Reaching for DISTINCT to "fix" a query that's actually producing duplicates because of an incorrect join — the real fix is the join logic, not papering over it with DISTINCT

Interview Relevance

A common trick question: "Will SELECT DISTINCT name and SELECT DISTINCT name, department return the same number of rows?" — not necessarily; the second can return more rows if the same name appears with different departments.

Practice Question

Write a query to list every distinct (department, job_title) combination that currently exists in an employees table.

Want to go beyond the notes?

Join Coding Now Tech Institute's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

SQL SELECT DISTINCT – FAQs

Quick answers about learning SQL SELECT DISTINCT in SQL.

This free note from Coding Now Tech Institute explains SQL SELECT DISTINCT in SQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every SQL topic on Coding Now Tech Institute, including SQL SELECT DISTINCT, is 100% free with no signup required.
With focused practice, most students grasp SQL SELECT DISTINCT in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now