ADVERTISEMENT

SQL SELECT DISTINCT

Sometimes, your query results have duplicates. To get only unique (different) values, we use DISTINCT.

🔹 How to Use DISTINCT

-- Get unique departments from employees
SELECT DISTINCT department FROM employees;

-- Multiple columns: unique combinations of those columns
SELECT DISTINCT department, job_title FROM employees;

🧠 What DISTINCT Does

  • Removes duplicate rows from the result
  • Works on all selected columns combined (if multiple columns selected)

⚠️ Notes

  • Using DISTINCT can slow down queries on large data sets — use only when needed
  • To remove duplicates on a single column, just select that column with DISTINCT

🧩 Quick Recap

ExampleWhat it does
SELECT DISTINCT department FROM employees;List of unique departments
SELECT DISTINCT department, job_title FROM employees;Unique department & job_title combos

✅ Simple and useful to clean up your data output!

ADVERTISEMENT