Leanpub Header

Skip to main content

SQL Mastery Series

A Problem-Solving Workbook — 84 Solved SQL Challenges from Beginner to Interview-Ready

This book is 100% completeLast updated on 2026-07-02

84 hand-picked SQL problems, fully solved and explained — from your first SELECT to interview-ready queries. Seven volumes of pure practice: a problem, the data, the answer, and why it works. No theory chapters, no filler, every query tested against a real database. Solve first, read second.

Minimum price

$11.00

$11.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

Buying multiple copies for your team? See below for a discount!

PDF
About

About

About the Book

Stop reading SQL theory. Start solving.

This book is 84 hand-picked SQL problems that take you from your first SELECT statement to genius-level analytical queries — the kind that show up in real technical interviews.

No theory chapters. No filler. Every single problem gives you a clear prompt, a sample input table, the exact expected output, a working solution, and a plain-English explanation of why it works — not just what to type.

The seven volumes rise one honest step at a time: Beginner → Easy-Medium → Medium → Medium-Hard → Hard → Expert → Genius. Volume 1 is single-table filtering and sorting. By Volume 7 you're computing medians without window functions, counting concurrent events, and finding the smallest missing positive integer — pure interview-grade challenges.

Every query in this book was tested against a real database before publishing. No broken code, no queries that only work in theory.

Who this is for

You already know the basics of SQL and want to get genuinely good at it. Whether you're preparing for a data or backend interview, leveling up from simple queries to window functions and CTEs, or just want deliberate practice instead of passive reading — this is your workbook.

How to use it

Solve each problem yourself first. Open any free SQL playground, recreate the table, and write your own query before reading the solution. The reading comes second; the typing comes first.

Note: examples use standard SQL. A few advanced solutions (window functions, PERCENTILE_CONT, recursive CTEs) target PostgreSQL-style engines; equivalents are explained where they differ.

146 pages · 7 volumes · 84 problems · one complete path from beginner to expert.

What's inside (you can add this as a bulleted section)

Volume 1 — Beginner: single-table filtering, sorting, basic conditions

Volume 2 — Easy-Medium: aggregation, GROUP BY, HAVING, CASE, NULL handling

Volume 3 — Medium: INNER/LEFT joins, subqueries, the classic NULL traps

Volume 4 — Medium-Hard: multi-table joins and CTEs

Volume 5 — Hard: window functions (ROW_NUMBER, RANK, running totals, medians)

Volume 6 — Expert: interview-grade problems — pivots, recursive CTEs, graph traversal, sargability

Volume 7 — Genius: everything at once — gaps-and-islands, concurrent events, hierarchies, the hardest patterns

Share this book

Categories

Team Discounts

Team Discounts

Get a team discount on this book!

  • Up to 3 members

    Minimum price
    $27.00
    Suggested price
    $27.00
  • Up to 5 members

    Minimum price
    $44.00
    Suggested price
    $44.00
  • Up to 10 members

    Minimum price
    $77.00
    Suggested price
    $77.00
  • Up to 15 members

    Minimum price
    $110
    Suggested price
    $110
  • Up to 25 members

    Minimum price
    $165
    Suggested price
    $165

Author

About the Author

Hatem M.

Hatem M. is a programmer and technical author whose work focuses on modern C++, large language models, and AI systems.

His books combine first-principles explanations with complete implementations and reproducible experiments. They include C++ Algorithmic Mastery, an eight-volume series on algorithms and problem solving; Build an LLM Inference Engine in C++, which constructs a GPT-style inference engine from scratch; LLM Quantization: From the Bits Up, which develops the theory and practice of neural network quantization from the bit level upward; and C++ Autopsy, a forensic investigation of ten subtle C++ bugs that compiled successfully, ran correctly, and still produced the wrong answers.

Contents

Table of Contents

What's Inside

7 Volumes · 84 Problems · One Complete Path

Volume 1 — Beginner

Single-table filtering, sorting, and basic conditions. Your foundation: SELECT, WHERE, ORDER BY, and reading a query the way the database does.

Volume 2 — Easy-Medium

Aggregation and grouping: GROUP BY, HAVING, CASE, and the NULL traps that quietly break beginner queries.

Volume 3 — Medium

Joins and subqueries enter the picture: INNER JOIN, LEFT JOIN, IN, EXISTS, and the recurring NULL pitfalls hiding inside them.

Volume 4 — Medium-Hard

Multi-table joins and Common Table Expressions (CTEs). Breaking a hard question into readable, composable steps.

Volume 5 — Hard

Window functions: ROW_NUMBER, RANK, DENSE_RANK, running totals, and medians — the tools that separate casual users from strong ones.

Volume 6 — Expert

Interview-grade problems: pivoting, recursive CTEs, graph traversal, cohort retention, and query sargability — where correctness alone is no longer enough.

Volume 7 — Genius

Everything at once: medians without window functions, gaps-and-islands, concurrent-event counting, hierarchies, and the smallest missing positive integer. The hardest patterns, one final time.

Every problem includes a prompt, sample input data, the expected output, a working solution, and a plain-English explanation. Every query tested against a real database before publishing.

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub