← All articles
Learning · August 1, 2026 · 7 min read

The 12 SQL cheat sheets that cover 95% of real query work

Most SQL cheat sheets are keyword dumps that answer nothing. These 12 free one-pagers are organized around the questions that actually block you at work: duplicate rows after a join, aliases that error, queries that ignore their index. Each one is a printable reference with real examples.

By D8A Academy

Search for a SQL cheat sheet and you get walls of keywords: every clause, every function, no hierarchy. That is a syntax dump, not a reference. Real query work fails in predictable places, a join that silently doubles revenue, an alias that errors in WHERE, an index the engine refuses to use, and a good cheat sheet is built around one of those failures. Here are the 12 free one-pagers that cover about 95% of the SQL you will write, grouped by the level where each problem shows up.

The 12 sheets at a glance:

  1. SQL JOINs
  2. WHERE vs HAVING
  3. SQL execution order
  4. The core SQL functions
  5. SQL dates
  6. NULL handling
  7. CTE vs subquery
  8. Window functions
  9. GROUP BY vs PARTITION BY
  10. JSON in SQL
  11. SQL indexing
  12. Slow query debugging

Why one-pagers beat the giant reference

A single mega-sheet with all of SQL on it optimizes for looking complete. A working reference optimizes for speed: you hit a wall, you scan one page, you get unblocked, you go back to work. That is why each of these sheets covers exactly one problem, states the trap in plain language, and shows the failing and working query next to each other. They are the same sheets D8A publishes daily as cheat sheets on social, collected here in the order you will actually need them.

Fundamentals: the four sheets that explain most errors

These four cover the mistakes that generate the majority of beginner and intermediate confusion. If you only bookmark one section, make it this one.

01

SQL JOINs

The 4 joins you actually use, plus the two traps that silently multiply rows and produce wrong numbers. Reach for it the moment a join returns more rows than the table you started with.

Duplicate rows
02

WHERE vs HAVING

Why WHERE AVG(salary) > 60000 errors every time: WHERE runs before groups exist. The one-word fix, and the performance trap of filtering in the wrong clause.

Aggregate errors
03

SQL execution order

You write queries top to bottom; the engine runs them in a different order. This one fact explains alias errors, WHERE vs HAVING, and half the confusing behavior in SQL.

The master key
04

SQL functions

The 25 functions that answer 80% of real queries, aggregates, strings, dates, NULLs, conditionals, each with a five-word gloss on one printable page.

The core 25

Start with SQL JOINs explained and the SQL execution order: together they preempt most of what stumps people in their first year. Then keep WHERE vs HAVING and the core SQL functions within reach for daily writing.

SQL JOINs cheat sheet: the four joins explained visually with Venn diagrams, example queries, and the two traps that produce silent wrong numbers
The SQL JOINs one-pager. Every sheet in this list follows the same format: one problem, the trap, and the failing and working query side by side.

Intermediate: where analyst work actually lives

Once joins and grouping feel automatic, day-to-day analytics runs on dates, NULLs, and window logic. These six sheets are the ones working analysts reach for weekly.

05

SQL dates

Truncate, extract, date math, the monthly report skeleton, and month-over-month growth with LAG. Every date pattern you keep googling, on one page.

Monthly reports
06

NULL handling

Why WHERE email = NULL matches zero rows, ever. Three-valued logic, IS NULL, COALESCE, and the two NULL traps that quietly empty your results.

Silent empties
07

CTE vs subquery

What each is for, a four-question decision rule, the CTE plus ROW_NUMBER top-N interview pattern, and the NOT IN trap that returns zero rows.

Readable queries
08

Window functions

A value per row, computed over a group, without collapsing anything. The anatomy, the ranking trio, and the top-N pattern interviews love.

Rank without collapsing
09

GROUP BY vs PARTITION BY

GROUP BY turns 200 rows into 3; PARTITION BY keeps all 200 and adds group context to each. The side-by-side queries and the rule of thumb that picks between them.

Collapse or keep
10

JSON in SQL

The Postgres jsonb operators decoded: reading keys, filtering, exploding arrays into rows, and the text trap hidden inside the double arrow.

Arrow operators

The details live in SQL dates, NULL handling, CTE vs subquery, window functions, GROUP BY vs PARTITION BY, and querying JSON in SQL. If you are prepping interviews, the window functions and CTE sheets carry the two patterns SQL screens test most.

Window functions cheat sheet: the anatomy of OVER and PARTITION BY, the ranking trio, and the top-N-per-group pattern
The window functions sheet, home of the top-N-per-group pattern SQL screens love.
The window function tell
If you can explain, without notes, why GROUP BY collapses rows while PARTITION BY keeps them, you are ahead of most candidates in a SQL screen. It is the single most common intermediate discriminator interviewers use, and two of these one-pagers exist specifically to make that distinction permanent.

Debugging and performance: when correct is not enough

Eventually a correct query takes 40 seconds and someone asks you why. These two sheets are the playbook for that conversation.

11

SQL indexing

The sorted-copy mental model, why the engine ignores an index wrapped in a function, the sargable rewrite that wakes it up, and when an index actually hurts.

Ignored indexes
12

Slow query debugging

How to read the actual plan instead of the query text, the three query shapes that silently kill indexes, and what to do when indexes are not enough.

EXPLAIN ANALYZE

Read SQL indexing first for the mental model, then the slow query playbook for the step-by-step diagnosis. Together they turn "it's slow" from a shrug into a procedure.

Slow SQL query debugging cheat sheet: reading EXPLAIN ANALYZE, the three query shapes that silently kill indexes, and what to do when indexes are not enough
The slow query playbook: read the plan, spot the index-killing shape, escalate deliberately.

How to actually use a cheat sheet

Collecting references feels like progress and changes nothing. The sheets earn their keep in exactly two modes, and both are active.

  1. 1

    Use them as a working reference

    Mid-task, a one-pager answers the specific question blocking you. That is lookup, and it is legitimate. What it is not is learning.

    Questions to ask
    • Keep them open while you write real queries
    • Scan for the trap, not the syntax
    • Thirty seconds, then back to work
  2. 2

    Drill them with recall practice

    Recall is what makes a pattern survive an interview or a live incident. Reading a sheet five times builds recognition; reproducing it once from memory builds the skill.

    Questions to ask
    • Read a sheet, close it
    • Rewrite the core pattern from memory
    • Check, note the gap, repeat tomorrow
  3. 3

    Apply them in a real project

    A cheat sheet proves you can look something up. A finished project proves you can use it. Only one of those gets you interviews.

    Questions to ask
    • Messy data, real business question
    • Joins, dates, windows in one analysis
    • Published where a recruiter can open it
A cheat sheet you read is trivia. A cheat sheet you can rewrite from memory, then apply to messy data, is a skill.
The rule behind every sheet in this list

That last step is the one that counts. SQL patterns only become hireable proof once they show up inside a finished analysis someone can open: a real dataset, a real question, a documented answer. If you want concrete places to apply these twelve sheets, start with our data analyst portfolio project ideas, or the broader list of data portfolio project ideas across roles. Every D8A path is built on exactly that principle: guided real projects where the joins, windows, and EXPLAIN plans stop being flashcards and become work you can defend.

Frequently asked questions

What should a good SQL cheat sheet contain?
Not a list of keywords. A useful SQL cheat sheet is organized around a problem: why a join duplicates rows, why an alias errors in WHERE, why a query ignores its index. It should show the failing query and the fixed query side by side, name the trap explicitly, and fit on one page so you can scan it in thirty seconds mid-task. If a sheet just lists syntax you could get from autocomplete, it is decoration.
How much SQL do I actually need for a data job?
Less than the documentation suggests and more than a beginner course covers. In practice you need joins, aggregation with GROUP BY and HAVING, the execution order, date handling, NULL logic, CTEs, and window functions. That set covers the overwhelming majority of production analytics queries. Indexing and query debugging matter once your tables stop being toy-sized. The twelve sheets in this article map exactly onto that list.
Are SQL cheat sheets good for interview prep?
Yes, with one condition: you must practice recall, not recognition. Interviews ask you to produce a working query under pressure, so read a sheet, close it, and rewrite the core pattern from memory. One-pagers are the right format because each covers a single interview staple, like the top-N-per-group pattern with ROW_NUMBER or the WHERE versus HAVING distinction, that screens test again and again.
Is SQL still worth learning in 2026?
Yes, and it is arguably the safest skill bet in data. Every analytics stack, every warehouse, and every BI tool speaks SQL, and AI assistants have made reading and debugging SQL more important, not less, because someone has to verify the generated query is right. Job postings for analyst, engineering, and science roles still list SQL more often than any other technical skill.

Keep reading