Getting started
Welcome to The Query Book
The Query Book is a hands-on handbook for learning SQL, the language used to query databases. It covers the essential concepts, with examples you can run and exercises with solutions, all connected to a built-in SQL console: nothing to install, everything runs in your browser.
Who am I?
My name is Kevin Rosamont Prombo. I have worked in data since 2012: first as a statistician, then as a data scientist and a data analyst, and today as a lead data.
Since 2020 I have also trained analysts: at EM Lyon Business School, at Albert School with Γcole des Mines, at UniversitΓ© Paris Nanterre, and for companies such as Pernod Ricard, Banque de Luxembourg and Le Wagon. Teaching showed me where beginners get stuck. This handbook brings together the explanations and exercises that helped them move forward.
Why this handbook?
You learn SQL by writing queries, not by reading definitions. Every chapter is therefore built so that you practise straight away:
- every example can be edited and run in place, on real tables;
- every question has its own answer area: your query is validated automatically as soon as its result is the expected one;
- every question has a commented solution, to open once you have tried.
Who is it for?
For anyone who wants to learn SQL, whatever their starting point: students, career changers, analysts still working in Excel, or future analytics engineers. The first chapters assume no prior knowledge; the last ones prepare you for technical interviews.
What you will learn
| Part | Chapters | What you will be able to do |
|---|---|---|
| Understand | 1 to 4 | Explain what a database, a data warehouse and a DBMS are, and who does what in a data team. |
| Writing SQL | 5 to 14 | Select, filter, sort, compute, group, join and stack tables; handle conditions, missing values and dates. |
| Structuring | 15 to 17 | Read a data model, break a query into steps with CTEs, master window functions. |
| In practice | 18 to 20 | Run a data analyst's analyses, test and model data like an analytics engineer, pass a technical interview. |
| Review | 21 and 22 | Find every concept on one page and know what to learn next. |
The data in this book
The examples use four databases. You will find them all in the console's Tables panel.
- controlGest, the main one: a French coffee wholesaler that sells capsules, pods, ground and whole-bean coffee, drinks and machines to supermarket chains, e-commerce sites and the food-service sector. It holds its customers, products, monthly sales from 2021 to 2026, sales reps, budgets, price lists and promotions.
- northWind: the orders of a food distributor, a classic sample database for joins.
- adventureWork: the online sales of a bicycle maker, organised as a star schema.
- personnel: a tiny table of employees, handy for following a calculation step by step.
Here, for example, is the wholesaler's monthly revenue in 2025. You will be able to write this query by chapter 10:
SELECT Date AS month,
ROUND(SUM("NOS (COPA)") / 1000000, 1) AS revenue_millions
FROM perform25
GROUP BY Date
ORDER BY DateBefore writing your first query, let's start by understanding what a database is and what it is for.