Choose whether duplicate values stay
Use DISTINCT when a result needs each projected value once.
What you are trying to do
A service directory needs a list of regions where items are stocked, with each region shown once.
Work through it
- Count the repeated North values in the source.
- Follow the Region expression through DISTINCT.
- Check the unique result values and their order.
Check your work
The result has two rows, North and South. DISTINCT removes repeated projected Region values.
Practice SQL
Open in SQL FlowSELECT DISTINCT Region
FROM (VALUES (N'North'), (N'North'), (N'South')) AS Stock(Region)
ORDER BY Region;
Knowledge check
Commands in this lesson
Next lesson Sort rows with a tie-breaker