SQL SELECT DISTINCT
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
DISTINCTcan 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
| 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 and useful to clean up your data output!
Was this helpful?
Thanks for your feedback!