The
DISTINCT
keyword allows you to find unique values in a column.
Once a table starts getting a lot of data in it, some columns will contain duplicate values.
For example, many Individuals share first names and surnames. Most of the time this isn't a problem. But sometimes you will want to find out how many unique values there are in a column. To do this you can use the
DISTINCT
keyword.SQL statement
SELECT DISTINCT(FirstName) FROM Individual;
Source Table
IndividualId | FirstName | LastName | UserName |
---|---|---|---|
1 | Fred | Flinstone | freddo |
2 | Homer | Simpson | homey |
3 | Homer | Brown | notsofamous |
4 | Ozzy | Ozzbourne | sabbath |
5 | Homer | Gain | noplacelike |
Result
In this example, using the
DISTINCT
keyword, all customers with the same first name are treated as one. This results in only one entry for Homer (even though there are three different entries in total).FirstName |
---|
Fred |
Homer |
Ozzy |
No comments:
New comments are not allowed.