Locked lesson.
About this lesson
Exercise files
Download this lesson’s related exercise files.
SELECT DISTINCT.docx58.9 KB SELECT DISTINCT - Solution.docx
59.4 KB
Quick reference
SELECT DISTINCT
Select Distinct allows us to return unique results.
When to use
Use it any time you want to find unique items.
Instructions
Select Distinct looks like this:
SELECT DISTINCT [First Name]
FROM [Customer].[dbo].[Current_Customers]
This will return only the unique first names in the customer database. For example if there are 5 people named John and 3 people named Sally, each of these names will only be displayed once in the results (not 5 and 3 times).
You can also use COUNT to count the number of unique records.
SELECT COUNT ( DISTINCT [First Name] )
FROM [Customer].[dbo].[Current_Customers]
This will return the total number of unique first names in the customer database.
Hints & tips
- Select Distinct lets you return unique results
- Be sure to specify a column, it can't return wildcard *
Lesson notes are only available for subscribers.