Data and messaging · 18 concepts
SQL
From the CRUD you know to joins, window functions, indexes, transactions and schema design, the way interviews ask them.
Asked in these mock interviews
Part 1 · 3 concepts
Querying
- 01
SELECT, WHERE, ORDER BY and how a query runs
A SELECT is written as SELECT ... FROM ... WHERE ... GROUP BY ... HAVING ... ORDER BY ... LIMIT, but it is logically evaluated as FROM, WHERE, GROUP BY, HAVING, SELECT…
- 02
NULL and three-valued logic
NULL means 'unknown', so any comparison with NULL (even NULL = NULL) gives unknown rather than true, WHERE keeps only rows where the condition is true, and aggregates…
- 03
Subqueries, EXISTS and CTEs (including recursive)
A subquery is a query inside another (scalar, IN/EXISTS, or a derived table); a correlated subquery runs per outer row; a CTE (WITH name AS (...)) names a subquery to…
Part 2 · 4 concepts
Joining and aggregating
- 04
JOINs: inner, left, right, full, self
INNER JOIN keeps only matching pairs, LEFT JOIN keeps every row from the left table and fills NULLs when there is no match, and a filter on the right table belongs in…
- 05
GROUP BY, HAVING and conditional aggregation
GROUP BY collapses rows into one row per group so aggregates (COUNT, SUM, AVG, MIN, MAX) work per group, WHERE filters rows before grouping, HAVING filters groups…
- 06
Window functions
A window function computes a value over a set of related rows (the window, defined by OVER (PARTITION BY ... ORDER BY ...)) without collapsing them, which gives…
- 07
Classic interview queries
A handful of query patterns come up again and again in live SQL rounds: Nth highest value, duplicates, rows with no match, top N per group, latest row per group and…
Part 3 · 3 concepts
Performance
- 08
Indexes: B-trees, composite and covering indexes
An index is a separate sorted structure (usually a B-tree) that lets the database find rows by a key in a few steps instead of scanning the table, and a composite index…
- 09
Reading query plans with EXPLAIN
EXPLAIN shows the plan the database chose (scans, joins, sorts and their estimated costs), EXPLAIN ANALYZE actually runs the query and adds real row counts and timings…
- 10
Pagination: OFFSET vs keyset
OFFSET pagination makes the database read and discard all skipped rows and shifts when rows are inserted, while keyset (seek) pagination filters for rows after the last…
Part 4 · 4 concepts
Correctness under concurrency
- 11
Transactions in SQL: BEGIN, COMMIT and ROLLBACK
In SQL, a transaction is BEGIN, your statements, then COMMIT, or ROLLBACK when anything fails, so the change happens fully or not at all. Keep it short, run it on one…
- 12
Isolation levels and anomalies
Isolation levels decide which effects of concurrent transactions you can see: Postgres defaults to Read Committed (each statement sees data committed before it…
- 13
Locking, oversell and optimistic concurrency
To stop two buyers taking the last item, either make the change atomic in one statement (UPDATE ... SET qty = qty - 1 WHERE qty > 0), lock the row while you decide…
- 14
Constraints: let the database guard your data
Constraints (PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, CHECK) make the database reject invalid data no matter which code path writes it, and a UNIQUE constraint is…
Part 5 · 2 concepts
Schema design
- 15
Data modelling and normalisation
Model each real-world thing as a table with a key, link them with foreign keys (one-to-many with a column, many-to-many with a junction table), and normalise so each…
- 16
When to denormalise
Denormalise on purpose when reads vastly outnumber writes and joins or aggregates become the bottleneck (counters, read models, materialised views, snapshots), and…
Part 6 · 2 concepts
Postgres features interviews ask
- 17
Upsert (ON CONFLICT) and RETURNING
INSERT ... ON CONFLICT (cols) DO UPDATE / DO NOTHING performs an atomic insert-or-update based on a unique constraint, and RETURNING gives back the affected rows in the…
- 18
JSONB in Postgres
JSONB stores JSON in a parsed binary form that can be queried with operators like ->, ->> and @> and indexed with GIN, which is good for flexible attributes, but data…
Your first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.