Minimum Viable SQL Patterns

26 ratings

Limited time inflation relief pricing

$14.99 $9.99

This is a book about SQL Patterns. Patterns describe problems that occur over and over in our professional settings. A pattern is a like a template that you can apply to different problems. Once you learn each one, you can apply them to solve problems faster and make your code more readable and easier to maintain.

Who am I

I’ve been writing SQL for ~15 years. I’ve seen and written hundreds of thousands of lines of code. Over time I noticed a set of patterns and best practices I always come back to when writing queries. These patterns made my code more efficient, easier to understand and a breeze to maintain.

Why did I write this book

I have a background in computer science. As part of the curriculum we learn how to make our code more efficient, more readable and easy to debug. As I started to write SQL, I applied many of these lessons to my own code. When reviewing other people’s code I would often spot the same mistakes.

Their queries were long, complex and slow. I would often have rewrite them just so I could understand what they were doing. I thought this was a known problem. So when people asked me how they could learn to do what I did, I looked around for a book or course that taught these patterns but couldn’t find one. I decided to write it myself and the result is this book.

Is this book for you?

This book is for anyone who is familiar with SQL and wants to take their skills to the next level. I don't cover any of the basic syntax here so make sure you have that down pat. I expect you to already know how to join tables and do basic filtering and aggregation.

If you find that your SQL code is often inefficient and slow and you want to make it faster, this book is for you!

If you find that your SQL code is long, messy and hard to understand and you want to make it cleaner, this book is for you!

If you find that your SQL code breaks easily when data changes and you want to make it more resilient, this book is for you!

What you'll learn in this book

I'm a huge fan of project-based learning. You can learn anything if you can come up with an interesting project to use it thing in. I used a project when I taught myself data science.

That's why for this book I designed an interesting and useful data project to organize it around. I explain each pattern as I walk you through the project. This will ensure that you learn the material better and remember it the next time you need to apply it.


  • Introduction
  • Chapter 1: Introducing the Project
    • Understanding the Data Model
  • Chapter 2: Core Concepts
    • Granularity
    • Granularity Manipulation
    • Granularity Multiplication
  • Chapter 3: Query Decomposition
    • Common Table Expressions (CTEs)
    • Decomposing Queries with CTEs
  • Chapter 4: Query Maintainability
    • Reusability Principle
    • DRY Principle
  • Chapter 5: Query Performance
    • Reducing Rows
    • Reducing Columns
    • Delaying Ordering
    • Bounded Time Windows
  • Chapter 6: Query Robustness
    • Dealing with Formatting Issues
  • Chapter 7: Finishing the Project

30-Day Money-Back Guarantee

If you are unhappy with your purchase for any reason, you can request a FULL refund within 30 days of purchase, no questions asked!

What Customers are Saying

"Just finished Minimal Viable SQL Patterns - great read! I have a few weeks before starting a new data analyst role at a FAANG company and your book gave me some excellent perspective & protips. Super useful & has me feeling more confident & prepared."

-Juan Sebastian Vasquez (@JuanSVas)

"The SQL patterns book of @ergestx is a very good resource if you want to step-up your sql skills. I can recommend it!"

-Tobias_Petry.sql (@tobias_petry)

I want this!
1,384 sales
Copy product URL


(26 ratings)
5 stars
4 stars
3 stars
2 stars
1 star

Minimum Viable SQL Patterns

26 ratings
I want this!