📇SQL quick reference
Dialect-stamp everything
Quick references speed recall of clause order, join diagrams, and datatype gotchas. They summarize relational patterns, they do not replace deep understanding of keys and NULLs. Note EXPLAIN and LIMIT/OFFSET syntax per engine; pasted snippets still need testing in your version.
Maintain an internal one-pager per engine version your organization actually runs, and refresh it after upgrades.
SELECT skeleton
SELECT col1, col2, agg(col3) AS metric
FROM t1
JOIN t2 ON …
WHERE …
GROUP BY col1, col2
HAVING …
ORDER BY metric DESC
LIMIT 100 OFFSET 0;| clause |
|---|
| FROM/JOIN → WHERE → GROUP BY → HAVING → SELECT → ORDER → LIMIT |
✂️Common snippets
Copy, then adapt keys and transactions.
| Task | Snippet |
|---|---|
| Insert row | INSERT INTO t(a,b) VALUES (1,'x'); |
| Upsert (PostgreSQL) | INSERT … ON CONFLICT (id) DO UPDATE … |
| Remove rows | DELETE FROM t WHERE …; |
Reference traps
- Outdated cheat sheets after upgrades.
- Mixing MySQL and Postgres locking or limit quirks incorrectly.
- Omitting transaction semantics on reference cards.
Make it trustworthy
- Version-stamp PDFs and internal wikis.
- Link references to runnable fiddle scripts.
- Include emergency contacts for database on-call.
- Cross-link to deeper lessons instead of duplicating long prose.
Logical order
When debugging, walk the standard pipeline in evaluation order, not top-to-bottom reading order, so aliases, aggregates, and windows land in the right mental bucket.
TL;DR
This page is a cheat sheet of common clauses and functions, accurate for teaching flow, but always confirm edge cases in your engine docs (NULL handling, limits, and reserved words differ). Use it as a navigation map: jump from here to the full lessons for joins, aggregates, isolation, and indexing before tuning production workloads.