Overview
List the countries your customers come from, each one once, and learn why DISTINCT applies to the whole row, not to the first column.
- SELECT DISTINCT
- It compares whole rows
- Sorting the result
Short Course
SELECT DISTINCT removes duplicate rows from the result. Trap: it compares
the whole row, so DISTINCT country, city keeps every different pair, not
one row per country.
SELECT DISTINCT country FROM customers; -- FR, DE
SELECT DISTINCT country, city FROM customers; -- FR Paris, FR Lyon, DE Berlin
Task
Return each country your customers come from, once, in alphabetical order.
In the database below, France appears three times but should be listed once.
Database
Sample data from the first test. The other tests use different rows, so write a query, not a list of answers.
| idINTEGER | nameTEXT | countryTEXT | cityTEXT |
|---|---|---|---|
| 1 | Ana | FR | Paris |
| 2 | Bo | DE | Berlin |
| 3 | Cy | FR | Lyon |
| 4 | Di | ES | Madrid |
| 5 | Eve | FR | Paris |
Test Suites
Pending
Next
Output