SQL SELECT DISTINCT

Article Summary

Sometimes, your query results have duplicates. To get only unique (different) values, we use DISTINCT. πŸ”Ή How to Use DISTINCT 🧠 What DISTINCT Does ⚠️ Notes 🧩 Quick Recap Example What it does SELECT DISTINCT department FROM employees; List of unique departments SELECT DISTINCT department, job_title FROM employees; Unique department & job_title combos βœ… Simple […]

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!

Was this helpful?