|
||
| Lesson 9
Objective |
The DISTINCT keyword
Understand how to use the DISTINCT keyword |
|
|
With the GROUP BY statement, you saw that you can limit results and remove duplicates in grouping situations.
Here is an example of the DISTINCT keyword:
What do you do if you want to remove duplicates but do not need to group the results? That is where the DISTINCT keyword comes in. DISTINCT is one of the easiest, most straightforward, most underused keywords in SQL. It is so simple and powerful that you will probably use it often in your queries. SELECT DISTINCT Email FROM MailingList
This statement will pull all the unique email values from the MailingList table and return them in the results set. These results
will be sorted based on email, and you will have no duplicates returned. You can see how this works in the image below:
To use the DISTINCT keyword, you simply indicate the column or columns that you want to be unique. In this case, we indicated that
the email value should be unique, but you can indicate columns from any table.
|
||
|
|
||