Start with the grain
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.
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.
- PostgreSQL and BigQuery: rows, columns, and workloadConnect point lookups and large aggregations to their storage and transaction behavior.
- 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.
Quick check
Take one query and say what one row represents after FROM, after GROUP BY, and in the final result. If the grain changes and you cannot explain why, revisit that step.