Articles
SQL bugs that look like mysteries until you see the one rule behind them. Each one is a real failure mode, explained properly.
Why Your LEFT JOIN Returns Too Many Rows
A LEFT JOIN doesn't return "one row per left-side thing." It returns one row per match. Here's the mental model that fixes duplicated totals for good.
WHERE vs HAVING — The Mistake Everyone Makes Exactly Once
"Aggregate function calls cannot appear in WHERE clause" isn't a random rule — it's a direct consequence of the order SQL actually executes in. Here's the model.
NULL Is Not Zero, and NOT IN Is Not Safe
A NOT IN subquery that silently returns zero rows is one of the most common production SQL bugs. It's caused by a single NULL, and it's invisible until it happens.
The N+1 Query Problem, Explained With the Bug You Already Shipped
Your app works fine in dev with 10 rows and falls over in production with 10,000. It's not a scaling mystery — it's one query hiding inside a loop.
Window Functions Explained With the One Mental Model That Actually Sticks
Window functions aren't a fancier GROUP BY. GROUP BY collapses rows. Window functions let every row see beyond itself without losing a single one.