Your SQL Cheat Sheet
Everything in one place.
Look how far you've come. At the start, you'd never written a query. Now you can join four tables, rank rows, build reports, clean messy data, and answer interview questions. Let's put everything on one page. Pause on any of these screens, and take a screenshot.

- From zero
- To reports and interviews
- Everything on one page
Reading data
First, reading data. Select picks columns. From picks the table. Where filters rows. Order by sorts. Limit keeps the first few. And distinct removes repeats. These six words answered every question in the first hour.
| Clause | What it does |
|---|---|
| SELECT | pick columns |
| FROM | pick the table |
| WHERE | filter rows |
| ORDER BY | sort |
| LIMIT | keep the first N |
| DISTINCT | remove repeats |
Summarising and joining
Next, summarising and joining. Count, sum, average, min, and max squash rows into numbers. Group by makes one answer per group. Having filters groups. Join and left join connect tables. And left join with is null finds what's missing.
| Tool | What it does |
|---|---|
| COUNT, SUM, AVG | many rows to one number |
| GROUP BY | one answer per group |
| HAVING | filter groups |
| JOIN | matching rows only |
| LEFT JOIN | keep every left row |
| LEFT JOIN + IS NULL | find what's missing |
Power tools
And the power tools. Subqueries and CTEs break problems into steps. Case makes categories, and pivots. Window functions rank rows, and add running totals, without squashing. And lag compares each row with the one before.
| Tool | What it does |
|---|---|
| Subquery, CTE | steps with names |
| CASE | categories and pivots |
| ROW_NUMBER, RANK | rank rows |
| SUM() OVER | running totals |
| LAG, LEAD | previous and next row |
| WITH RECURSIVE | hierarchies, calendars |
The mistakes to remember
And here are the mistakes this course warned you about. Forgetting the where on update or delete. Using equals null, instead of is null. Not in with a null in the list. Double counting after a join. Whole number division. And comparing text with the wrong capital letters. Each one runs without warning, so they're worth remembering.
| Mistake | The fix |
|---|---|
| UPDATE / DELETE, no WHERE | write WHERE first |
| = NULL | IS NULL |
| NOT IN with a NULL | NOT EXISTS |
| Double counting | COUNT(DISTINCT ...) |
| 140 / 1598 = 0 | use 100.0 |
| 'fantasy' vs 'Fantasy' | LOWER() both sides |
The habits that matter
Finally, the habits that matter more than any keyword. Check every step before building the next one. Write the where before you update, or delete. Watch out for nulls. Check row counts after joins. And when something looks too good, be suspicious.
Summary
That's the whole course on one page. Now, let's talk about what comes next.
Key takeaways- Read: SELECT ... WHERE
- Summarise and join
- CTEs and windows