Select customer names
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.
Select every customer name in ascending customer id order. Preserve repeated names.
Return columns name. Use the specified ordering; ties must be resolved as described.
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.
What this exercise practices
Choose output columns without changing the number of source records. This is the foundation for reasoning about repeated names and the meaning of one SQL result row.
Common mistakes and boundary checks
- Repeated names belong to separate customer records; DISTINCT would remove required output.
- Order by customer id even though id is not part of the requested output.
- An empty table should produce zero rows with the requested column name.
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.
- Choose one output column.
- Order by id even though id is not returned.
Worked solution
Try your own approach first, then compare the reasoning.
SELECT name FROM customers ORDER BY idProjection selects columns without deduplicating records.
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.