Most SQL interview practice stops at the point where the query runs. In an interview, the query almost always runs. What separates candidates is whether the number it returns is the number somebody actually asked for.
This book is sixty problems, each one built around a specific way to be silently wrong:
a join that quietly doubles your revenuea NOT IN that returns nothing, and no errora window frame that averages seven rows when you asked for seven daysa cohort chart whose empty cells look like a collapse in retentiona LEFT JOIN undone by the WHERE clause beneath itYou practise on a real database, not a toyNine tables. 186,000 listening events. Three years of billing, subscriptions, support tickets and plan changes. One file, five minutes, PostgreSQL or Docker on Windows, macOS or Linux. The data is generated from fixed rules, so your results match the printed ones to the cent.
Every query in this book was executed before it was printedEvery result you see was copied from a real run against that database, not typed from memory. Where a measured result contradicted what the author expected, and twice it did, the book prints the measurement and says so.
What is insidePart 1 Warm-ups that hide a trap. Part 2 Joins, and the rows you did not mean to create. Part 3 Aggregation. Part 4 Subqueries and CTEs. Part 5 Window functions, the largest part. Part 6 Dates, cohorts and retention. Part 7 Text and JSON. Part 8 Nine timed interview simulations with no hints.
Each problem gives you the ask, the shape of the answer, three hints you can take one at a time, a worked solution, a discussion of what the trap was, and a note on what the interviewer is listening for.
Back matter includes the same operations on MySQL, SQL Server, Snowflake and BigQuery, and an index of all sixty traps by category, the page to read the night before.
Who this is forYou can already write SELECT, WHERE, GROUP BY and a basic join. You are applying for data analyst or analytics engineering roles. You freeze when the interviewer says "now rank each customer by spend within their region."
If you have never written SQL before, start elsewhere and come back.