SQL · Level 1 Basics

SQL DISTINCT

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

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

Return each country your customers come from, once, in alphabetical order. In the database below, France appears three times but should be listed once.

Sample data from the first test. The other tests use different rows, so write a query, not a list of answers.

customers 5 rows
idINTEGERnameTEXTcountryTEXTcityTEXT
1AnaFRParis
2BoDEBerlin
3CyFRLyon
4DiESMadrid
5EveFRParis
solution.sql
Test Suites Pending
Output