solulubeta
Sign in
Cheat Sheets / Coding
02.04 · Cheat sheet

SQL

Query order, joins, GROUP BY vs HAVING, NULL rules, window functions, CTEs and the classic interview queries on one page.

3 min Cheat sheet Pro

The SQL you need for online tests and interviews.

Order of a query

Written: SELECT → FROM → WHERE → GROUP BY → HAVING → ORDER BY → LIMIT

Run: FROM / JOIN → WHERE → GROUP BY → HAVING → SELECT → DISTINCT → ORDER BY → LIMIT

That’s why a SELECT alias can’t be used in WHERE, but can be used in ORDER BY.

Joins

JoinReturns
INNERRows that match in both
LEFTAll left rows; NULLs where there’s no match
RIGHTAll right rows
FULL OUTERAll rows from both
CROSSEvery pair of rows
SELFA table joined to itself

Rows with no match: LEFT JOIN b ... WHERE b.id IS NULL, or NOT EXISTS.

solulu Pro

Continue this cheat sheet with Pro

Inside: 8 sections.

  • Order of a query
  • Joins
  • Grouping
  • NULL rules
  • Window functions
  • Classic queries
  • +2 more
Lifetime ₹1,999 ₹999 · Launch offer
Mark this as done when you are finished.

Item 8 of 12 · updated 2026-10-13