Understand the concept
SELECT chooses output columns; FROM identifies the source table. Before filtering, identify the grain: one order, one customer or one event. A customer name is not a reliable key because two people may share it. Use the id to relate records and keep only the requested columns.
Apply the method
WHERE removes rows before grouping. AND requires both predicates; OR accepts either. Parentheses make mixed conditions explicit. BETWEEN includes both endpoints. For dates, >= start AND < next_period extends cleanly to timestamps.
Avoid a common mistake
ORDER BY is the only promise of output order. Add a unique tie-breaker before LIMIT. DISTINCT removes duplicate output rows, not duplicate underlying entities. Check whether the question wants all orders or unique customers.
Worked query
Return id and name for all customers, ordered by id.
SELECT id,name FROM customers ORDER BY id;Run and explore this example →Check your understanding
Before running your query, predict the output columns and approximate row count. After running it, inspect a missing value, a tie and a record with no match when available. Explain why the result answers the question.
Practice this topic
- Customer directory — Return id and name for all customers, ordered by id.
- UK customer list — Return name for UK customers, ordered alphabetically.
- Paid orders — Return id and amount for paid orders, ordered by id.
- Large orders — Return id and amount for orders of at least 100, ordered by id.
- Affordable products — Return name and price for products priced between 15 and 40 inclusive, ordered by price then id.
- Country coverage — Return distinct country values alphabetically.
- Available hardware — Return name for Hardware products with stock greater than zero, ordered by id.
- Find workbooks — Return name for products whose name ends in workbook, ordered by name.
- Three most expensive — Return name and price for the three most expensive products, breaking ties by id.
- March activity — Return id for March 2026 orders, ordered by id. Use a half-open date range.
SQLite reference: SQL language documentation. Written by Future Data Academy with AI assistance; query examples checked against the supplied teaching dataset.
