What’s inside.
Each chapter ends with exercises and worked solutions you can check by hand.
- 00
Set up the shop database
Install SQLite, load the practice data, and learn the four steps of a good answer.
- 01
SELECT, WHERE and ORDER BY
Show the three highest-paid employees, and the NULL sort that changes the answer by database.
- 02
NULL, the trap in every interview
Why a “not equal” test loses rows, and why COUNT(*) and COUNT(column) can differ.
- 03
GROUP BY and HAVING
Find departments with an average salary above 90,000, and when to use WHERE instead.
- 04
Joins
INNER, LEFT, RIGHT and FULL joins, and two traps that give a wrong count with no error.
- 05
Finding what is missing
Find customers who never ordered, three ways, and why NOT IN can return nothing.
- 06
Self joins
Find employees who earn more than their manager, by joining a table to itself.
- 07
Subqueries and CTEs
Find customers who spent more than the average customer, with and without a named step.
- 08
Second highest salary
The classic question, three ways, extended to the Nth highest, with ties and empty results.
- 09
ROW_NUMBER, RANK and DENSE_RANK
What a window function is, and how the three differ on tied salaries.
- 10
Top N and latest row per group
Top two earners in each department and each customer’s latest order, with PARTITION BY.
- 11
Running totals, LAG and LEAD
Monthly revenue, the change from the month before, and the running total.
- 12
Duplicates
Find repeated emails, then remove the extras without losing any orders.
- 13
Dates, strings and CASE
A monthly report with one column per status, and where date and text functions differ.
- 14
Gaps and islands
Find customers who ordered on at least three days in a row.
- 15
Keys, constraints and normalization
Primary, unique and foreign keys, and 1NF, 2NF and 3NF in words an interviewer accepts.
- 16
Indexes and transactions
Fix a slow query and prove the fix worked, then ACID and isolation levels.
- 17
Mock interview
Twenty mixed questions with no chapter title to help, and a theory sheet to read before the real thing.