When DISTINCT is applied to multiple columns, SQL returns unique combinations of values across all selected columns.
Understanding multiple-column DISTINCT prevents incorrect assumptions about how duplicates are identified.
Find unique combinations of department and job title.
SELECT DISTINCT
Department,
JobTitle
FROM Employees;
Analysts can use this technique to discover unique business combinations such as region-product, department-role, or customer-city pairs.
- DISTINCT evaluates the complete selected combination.
- Duplicate combinations are removed.
- Each selected column contributes to uniqueness.
- It does not make each column unique independently.
- It is useful for categorical analysis.
How does DISTINCT work with multiple columns?
It returns unique combinations of values across all selected columns.
Will DISTINCT make each selected column individually unique?
No. DISTINCT makes the complete combination of selected column values unique.