Unique values
Part of the Fundamentals section of Coddy's SQL journey — lesson 4 of 72.
Let's assume we have the following table:
sales
| country | city | amount | |
|---|---|---|---|
| 1 | Poland | Warsaw | 13 |
| 2 | Germany | Berlin | 24 |
| 3 | Poland | Katowice | 56 |
And we would like to know all of the countries where the product was sold.
If we use the normal query we know: SELECT country from sales it will return Poland, Germany, Poland. This is not what we are looking for because Poland is repeated twice.
To solve it we can use the DISTINCT keyword:
SELECT DISTINCT country FROM salesChallenge
EasyAvailable tables and columns:
<strong>sales</strong>:<strong>coin</strong>,<strong>amount</strong>
Fetch all of the unique coins that were used in the sales table
Cheat sheet
Use DISTINCT to get unique values from a column:
SELECT DISTINCT column_name FROM table_nameWithout DISTINCT, duplicate values will be returned. With DISTINCT, each unique value appears only once in the result.
Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns