SELECT DISTINCT country FROM customers lists each country once. With several columns, DISTINCT applies to the whole combination.
COUNT(DISTINCT customer_id) counts unique values, which is how you count customers rather than orders.
Worked example
Which sales channels have been used?
SELECT DISTINCT channel FROM orders ORDER BY channel;
| channel |
|---|
| app |
| marketplace |
| web |
Common mistakes
- Using DISTINCT to hide duplicates created by a wrong join instead of fixing the join.
- Expecting DISTINCT to apply to only one of several selected columns.