Skip to content
Quantoros

List each city that appears in the customers table exactly once (no duplicates). Table definitions (from the source…

SQLLevel: FoundationBasics and filtering

List each city that appears in the customers table exactly once (no duplicates).

Table definitions (from the source exercise):

CREATE TABLE customers(customer_id INTEGER PRIMARY KEY, name TEXT, city TEXT, signup_date TEXT, credit_score INTEGER);
Hints
  • Define one output row and the source-table keys.
  • Check duplicates, NULLs and the order of filtering and aggregation.

Answer

Approach: One keyword does all the work here.

SELECT DISTINCT city FROM customers;

The source uses SQLite with a MySQL compatibility layer. Date and string functions are dialect dependent; the query is preserved as published.

Source and licence: SQL Practice Lab — Ebrahim Sharifi · MIT

Related questions