ComputingSQL

SQL Cheat Sheet — 1-page PDF

SELECT, joins, subqueries, set ops, DML/DDL, indexes, windows, normalization. The whole course on one dense, printable page for your midterm or final, with every formula typeset and worked examples where they help.

The first part is free below. See pricing →

For a specific exam: Databases (SQL) Final exam study sheet.

  • 1 pageUS Letter
  • 10 sections10 topics
  • Free previewfull sheet with Unlimited
Preview of the one-page SQL cheat sheet: SELECT, joins, subqueries, set ops, DML/DDL, indexes, windows, normalization Cheat sheet locked
the whole course, one page

On the sheet

What’s on it

The topics a typical SQL exam tests, all on the one page.

  • SELECT, WHERE, ORDER BY
  • Aggregates and GROUP BY, HAVING
  • JOIN types
  • Subqueries
  • Set operations
  • INSERT, UPDATE, DELETE
  • DDL: CREATE, ALTER, constraints
  • Indexes
  • Window functions
  • Normalization

Free preview

The free part, as text

The free part of the sheet, section by section. Unlock the full sheet to read the rest, edit any block, and print it or save it as a PDF.

01SELECT Basics

Query order
Logical eval: FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT/OFFSET.
SELECT [DISTINCT] expr AS alias, ...
FROM table
WHERE condition
ORDER BY col1 ASC|DESC, col2;

Projection

SQL SELECT attrs FROM R (after row filtering).

  1. * = all columns.
  2. AS = rename output expr/column.
  3. DISTINCT removes duplicate result rows.
  4. ORDER BY sorts after SELECT; default ASC.
  5. NULLS FIRST/LAST if supported.

Watch out:WHERE cannot use aggregate results; use HAVING after GROUP BY.

Ex.Get distinct department ids, largest first.

SELECT DISTINCT dept_id FROM Emp ORDER BY dept_id DESC;

02Filtering

Predicates

BETWEEN, IN, LIKE, IS NULL

IS NULL/IS NOT NULL for missing values; LIKE uses % any string, _ one char.

03Aggregates

WHERE vs HAVING

ClauseActs onCan use agg?
WHERErows before groupingNo
HAVINGgroups after groupingYes

Ex.Departments with > 5 employees.

SELECT dept_id FROM Emp GROUP BY dept_id HAVING COUNT(*) > 5;

04Joins

Join
Combine rows from tables by a predicate.

Join types

TypeRows kept
INNER JOINmatches only
LEFT JOINall left + matches
RIGHT JOINall right + matches
FULL JOINall rows from both
CROSS JOINCartesian product
SELECT e.name, d.dept_name
FROM Emp e
INNER JOIN Dept d ON e.dept_id = d.dept_id;

Cartesian

CROSS JOIN if no join condition.

Watch out:Put join condition in ON for outer joins; moving it to WHERE can remove null-extended rows and change semantics.

05Set Ops

Set operation rules

OpDuplicatesCols
UNIONremoved by defaultsame count/types
UNION ALLkeptsame count/types
INTERSECTremoved by defaultsame count/types
EXCEPTremoved by defaultsame count/types
SELECT city FROM A
UNION
SELECT city FROM B;
  1. Each query must have same number of columns.
  2. Corresponding columns must be type-compatible.
  3. ORDER BY applies to final combined result (usually only once at end).

Watch out:Set ops combine result sets; they do not join columns side-by-side.

06DML

DML
Data manipulation: INSERT, UPDATE, DELETE (and often MERGE).
INSERT INTO Emp(emp_id, name, salary)
VALUES (1, 'Ana', 90000);

UPDATE Emp
SET salary = salary * 1.05
WHERE dept_id = 10;

DELETE FROM Emp
WHERE emp_id = 1;

07DDL & Constraints

  1. DEFAULT x supplies value when omitted.
  2. REFERENCES T(c) targets candidate key in T.
  3. ON DELETE/UPDATE CASCADE|SET NULL|RESTRICT controls FK action.

Watch out:A foreign key value must match a referenced key value, or be NULL if allowed.

08Indexes

Index
Auxiliary structure to speed lookup/sort/join; extra storage + slower writes.
CREATE INDEX idx_emp_dept ON Emp(dept_id);
DROP INDEX idx_emp_dept;

When useful

Good forLess useful
frequent WHERE / join colstiny tables
high-selectivity colscolumns updated often
ORDER BY / GROUP BY supportlow-selectivity cols

Selectivity

Higher selectivity often => better index payoff.

  1. Composite index order matters: leftmost prefix usable.
  2. Covering index can satisfy query from index alone.
  3. Unique index enforces uniqueness if supported.

Cheat sheet locked

Also on the full SQL sheet

9 more sections, with every definition, formula and worked example. Unlimited unlocks every full sheet in the library to edit, print or save as a PDF, and makes unlimited sheets from your own notes.

Filtering

  • Common WHERE forms

Aggregates

  • Aggs
  • Grouping
  • Grouping rule

Joins

Subqueries

  • Subquery
  • Subquery use
  • Exists

Set Ops

  • Union family

DML

  • Transactions

DDL & Constraints

  • DDL
  • Constraints

Indexes

Windows & Normalization

  • Window function
  • Window clauses
  • Common windows
  • Normalization
  • Normal forms

Unlock the full sheet $4.99 a month or $19 a semester

FAQ

Questions

About the SQL sheet and making your own.

What does this SQL cheat sheet cover?
It has 10 sections: SELECT Basics, Filtering, Aggregates, Joins, Subqueries, Set Ops, DML, DDL & Constraints, Indexes and Windows & Normalization. Together they cover the topics a typical SQL exam tests, including SELECT, WHERE, ORDER BY, aggregates and GROUP BY, HAVING, JOIN types and subqueries.
Is the SQL cheat sheet free?
The first part is free to read on this page, with no account needed. The full sheet opens in the app with Unlimited ($4.99 a month or $19 for a semester), where you can edit it, print it or save it as a PDF. It is one US Letter page and prints cleanly in black and white or colour.
Can I bring this SQL cheat sheet to my exam?
Only if your course allows a note sheet, so check the syllabus. This one is a single US Letter page. If your exam allows a different size, such as a 3x5 or 4x6 index card or one page front and back, Cheat Sheet AI makes one at exactly that size from your own lecture notes.
How accurate is it?
The sheet was written by our engine from a standard course outline, then a second model fact-checked every formula and statement against it; it corrected 2 statements before publishing. Notation and emphasis vary between courses, so check it against your own lecture notes.
Can I make a SQL sheet from my own notes?
Yes. Upload your lecture slides, notes or study guide and Cheat Sheet AI writes a sheet in your course's notation, sized to exactly the space your exam allows. Your first sheets are free.

Your course, your notes, one page.

Make this from your notes

Upload your own SQL slides or notes and get a study sheet in your course’s notation. Your first sheet needs no account, and a free account adds one more. See pricing