Start with what one row means
SQL becomes easier when you can name the input population and required output grain before choosing syntax. This chapter connects tables, keys, types, and logical query order so later joins and windows have a clear foundation.
Suggested route: Read grain and logical query order first, then follow one query through parsing, planning, and execution. Use the practice dataset to predict results before checking the engine.
By the end: Explain why a query returns one row per customer rather than one row per order; distinguish logical SQL order from the physical plan the database actually executes.
Decision reference
| Question | Construct |
|---|---|
| Which rows are eligible? | FROM, JOIN, WHERE |
| What is the reporting grain? | GROUP BY and aggregates |
| Which groups qualify? | HAVING |
| Which comparisons retain detail? | Window functions |
| Which rows are displayed first? | Final ORDER BY, LIMIT |
In this chapter
- Think in rows and grainEstablish what one input and output row represents.
- Query structure & execution orderUnderstand logical clause order and what to optimize while writing the query.
- How a query actually runsFollow SQL through parsing, planning, execution, and returned rows.
- Relational databases & SQL commandsUnderstand relations, keys, and the jobs different SQL statements perform.
- Data types & castingChoose representations that preserve precision and meaning.
- Practice dataset & example conventionsUse a small, deterministic PostgreSQL dataset to run the handbook's core queries.
How to study
Use the suggested route above. For each lesson, explain the decision in your own words, test its example, and identify a situation where a different approach would be needed.