Preserve duplicate cities
Difficulty: Easy
Try your first run
No account is needed to try this exercise. Write your answer, run the tests, and use the feedback to improve it.
- Read the supplied table schema and expected output columns.
- Write one read-only query in the editor, then select Run code.
- Compare the result tables. Use Hints if you are unsure what to try next.
Return the city of every customer. Do not remove duplicates.
Return columns city. Row order does not matter; duplicate rows still count.
Schema and sample data
CREATE TABLE customers (id INTEGER PRIMARY KEY, name TEXT, city TEXT, email TEXT);
CREATE TABLE orders (id INTEGER PRIMARY KEY, customer_id INTEGER, amount_cents INTEGER, status TEXT, ordered_on TEXT);
CREATE TABLE returns (id INTEGER PRIMARY KEY, order_id INTEGER, amount_cents INTEGER);orders
| id | customer_id | amount_cents | status | ordered_on |
|---|---|---|---|---|
| 1 | 1 | 1200 | paid | 2026-01-02 |
| 2 | 1 | 800 | refunded | 2026-01-03 |
| 3 | 2 | 1200 | paid | 2026-02-01 |
| 4 | 99 | 0 | pending | 2026-02-02 |
returns
| id | order_id | amount_cents |
|---|---|---|
| 1 | 1 | 200 |
| 2 | 1 | 100 |
| 3 | 2 | 800 |
customers
| id | name | city | |
|---|---|---|---|
| 1 | Ada | Austin | a@example.test |
| 2 | Bo | Dallas | NULL |
| 3 | Cy | Austin | a@example.test |
Each test uses a fresh database. Column names must match the requested aliases.
Constraints
Use one SQLite SELECT query, optionally with CTEs. No writes, uploads, network, or extension loading. Data is synthetic. Integers are cents; do not use floating-point money. Each test has at most 1,000 rows per table. Medium exercises combine query stages; no database index is assumed.
Review lesson: Tables, rows, and output contractsA little nudge
Reveal one hint at a time. Give yourself a moment to try it.
- Do not use DISTINCT.
- A table is a collection of rows, not a set of values.
Worked solution
Try your own approach first, then compare the reasoning.
SELECT city FROM customersSQL SELECT preserves duplicates unless explicitly told otherwise.
Complexity
Inspect the logical plan with the lesson discussion: scans are linear in input rows; grouping and ordering may require temporary structures and sorting. Joins may be quadratic without useful indexes. This is a query-planning bound, not a timing guarantee.
Ready when you are
Write your solution, then run it against the practice tests.
Press Esc, then Tab to leave the editor. Code runs in an isolated browser workspace. Tests support learning, not verified grading.