The Marquee's four tables are built; this chapter is where you finally start asking them things. Every page turns a plain-English question Lora actually has — what's on tonight, which films run under 100 minutes, how many bookings does each screening have — into a query you can read out loud, and shows the answer that comes back. By the end you can filter, sort, compute, and count, which covers most of the SQL most people ever write.
6 topics
So far the database has mostly listened: Chapter 2 declared the tables, the types, and the keys, and the data settled into its shape. Now the direction reverses. A query is a question written in SQL, and SELECT is the word that starts every question. This chapter has one promise, and it is the best promise in the book: every question Lora can say in English about her cinema can be said in SQL too, usually in one short sentence that reads almost the same way.
The six topics build one skill in layers. First the bare SELECT — ask for columns, get a table back. Then WHERE narrows the rows, ORDER BY and LIMIT put the answer in order and cut it to size, and expressions let a query compute things that were never stored. The last two topics change what a row of the answer even means: GROUP BY collapses many rows into counts and sums, and HAVING filters those groups the way WHERE filters rows. Nothing in this chapter ever changes the data — reading is perfectly safe, so you can be as curious as you like.
The chapter's whole promise — a question becomes a query becomes an answer
The question, in English"What's on tonight after seven?"
→
The question, in SQLSELECT screen, starts_at FROM screenings WHERE …
→
The answer — a tablethree rows: 19:30, 20:00, 21:45