Menu
Coddy logo textTech

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

 countrycityamount
1PolandWarsaw13
2GermanyBerlin24
3PolandKatowice56

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 sales
challenge icon

Challenge

Easy

Available 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_name

Without DISTINCT, duplicate values will be returned. With DISTINCT, each unique value appears only once in the result.

Try it yourself

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals