02.04 · Cheat sheet
SQL
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
| Join | Returns |
|---|---|
| INNER | Rows that match in both |
| LEFT | All left rows; NULLs where there’s no match |
| RIGHT | All right rows |
| FULL OUTER | All rows from both |
| CROSS | Every pair of rows |
| SELF | A 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
Item 8 of 12 · updated 2026-10-13