Cheatsheets
SQL cheatsheet
Selects, joins, aggregates, and indexes you will actually type.
Query
| Command / topic | What it does |
SELECT a, b FROM t WHERE x = 1; | Filter rows |
SELECT * FROM t ORDER BY created_at DESC LIMIT 20; | Latest rows |
SELECT COUNT(*) FROM t GROUP BY status; | Aggregate by group |
SELECT DISTINCT country FROM users; | Unique values |
Joins
| Command / topic | What it does |
INNER JOIN b ON a.id = b.a_id | Matching rows only |
LEFT JOIN b ON a.id = b.a_id | Keep left rows even without matches |
EXISTS (SELECT 1 FROM b WHERE …) | Correlated existence check |
Schema helpers
| Command / topic | What it does |
CREATE INDEX idx_users_email ON users(email); | Speed up lookups |
EXPLAIN QUERY PLAN …; | Inspect how SQLite plans a query |
BEGIN; … COMMIT; | Wrap changes in a transaction |
← All cheatsheets · Courses