SQL Atlas

MySQL + PostgreSQL · pattern-first practice

Stop memorizing queries.
Recognize the shape.

A staff-level SQL field guide with every current LeetCode Database problem organized by the reusable idea that solves it.

pattern_05.sql portable
-- top N per group
WITH ranked AS (
  SELECT *,
    DENSE_RANK() OVER (
      PARTITION BY team_id
      ORDER BY score DESC
    ) AS place
  FROM results
)
SELECT *
FROM ranked
WHERE place <= 3;
98Unlocked problems
15Reusable patterns
2SQL dialects
98MySQL + PostgreSQL

SQL toolkit · learn the language

Know what every tool is for.

Learn the operator, when to reach for it, how to reason with it, the failure modes, and the MySQL/PostgreSQL differences.

The mental index

Every question has a shape.

Start with the data relationship, not the syntax. These patterns cover the recurring structures behind SQL interview questions.

98 unlocked LeetCode problems

Find the pattern. Write the query.

Loading the catalog…

Staff engineer playbook

A query is a proof.

Before optimizing, make the grain, invariants, edge cases, and tie-breaking rules explicit.

  1. 01

    Declare the grain

    Write one sentence: “one output row represents…” Most wrong joins begin with an unstated grain.

  2. 02

    Sketch cardinality

    Mark every relationship as one-to-one, one-to-many, or many-to-many before joining.

  3. 03

    Choose the pattern

    Translate the prompt into ranking, anti-join, rolling window, gaps and islands, or another known shape.

  4. 04

    Design the counterexamples

    Test nulls, duplicates, empty groups, boundary dates, and ties—not just the happy path.

  5. 05

    Read the plan

    Use EXPLAIN, verify row estimates, and optimize the biggest cardinality reduction first.