How a backend reads and changes data safely: transactions under concurrency, then the SQL you write every day (joins, GROUP BY, window functions). The joins, GROUP BY and window pages use the same small food-delivery database (customers, restaurants, orders, menu items), with the SQL and the Drizzle (TypeScript) version side by side and the table shown after each step. The transactions page uses a small shoe shop instead.

Reading order

  1. Quick revision: the whole subject on one page, for the night before an interview.
  2. Transactions and concurrency: lost updates, isolation levels, FOR UPDATE vs SERIALIZABLE and retry. (detailed)
  3. Joins: inner join, left join, and finding rows with no match. (detailed)
  4. Aggregates: GROUP BY and HAVING: piles, count(*) vs count(col), WHERE vs HAVING. (detailed)
  5. Window functions: top N per group with rank, running totals, LAG. (detailed)