When DISTINCT is applied to multiple columns, SQL returns unique combinations of values across all selected columns.
Understanding this behavior prevents confusion when duplicate values exist in individual columns but combinations are different.
Find unique combinations of department and city for employees.
SELECT DISTINCT
Department,
City
FROM Employees;
It is useful for analyzing unique business combinations such as region-category, department-location, and customer-product relationships.
- DISTINCT evaluates all selected columns together.
- A repeated value in one column can still appear.
- The complete combination must be unique.
- It is useful for combination analysis.
- DISTINCT does not modify source data.
How does DISTINCT work with multiple columns?
It returns unique combinations of values across all selected columns.
Can a department appear multiple times with DISTINCT?
Yes. If the department is associated with different values in another selected column, each unique combination can appear.