Interview Q&A · SQL
SQL Interview Questions & Answers
All 192 SQL interview questions — fundamentals, filtering, aggregations, JOINs, constraints, set operations, subqueries and CTEs, window functions, indexes, transactions, design and security — with correct, modern answers. This bank holds 192 questions across 17 topics and 12 topic groups. Every answer is written for current SQL versions, and each topic links to matching course lessons where they exist.
Every topic below links to its own page with all of its questions in one place.
Answers are checked against current language behaviour; old-guide claims are corrected.
Each topic points to the matching course lesson, and lessons point back here.
Featured questions in this bank
SQL Fundamentals
What is SQL?
SQL (Structured Query Language) is the declarative standard language for storing, querying and managing data in relational databases. You describe what result you want (SELECT ... WHERE ... GROUP BY), and the database engine…
Read the full answer →SQL Fundamentals
Why use a database instead of a spreadsheet or flat files?
Databases enforce structure (types, constraints), handle concurrent writers safely (transactions, locking), answer ad-hoc questions over millions of rows in milliseconds (indexes, query planner), and guarantee durability…
Read the full answer →SELECT Essentials
What is the logical order of query execution (why WHERE cannot use SELECT aliases)?
SQL executes FROM, then WHERE, GROUP BY, HAVING, SELECT, ORDER BY, LIMIT — definition order (SELECT first) is not execution order. WHERE runs before SELECT, so it cannot see column aliases; ORDER BY runs after, so it can. GROUP…
Read the full answer →SELECT Essentials
How do column aliases (AS) work?
AS renames an output column (SELECT salary * 12 AS annual) for readability and client consumption. The AS keyword is optional but recommended; aliases with spaces need quoting ("annual pay"). Aliases are usable in ORDER BY but…
Read the full answer →UPDATE, DELETE & Safe Writes
How do UPDATE and DELETE work?
UPDATE SET assigns new values to matching rows; DELETE removes matching rows. Both take WHERE — without it, every row changes. Both run inside transactions, so wrapping in BEGIN ... COMMIT/ROLLBACK makes them reviewable and…
Read the full answer →UPDATE, DELETE & Safe Writes
How do you update safely in production (guarded writes)?
Preview with SELECT COUNT(*) on the same WHERE, run inside an explicit transaction, verify ROW_COUNT, then COMMIT — with a ROLLBACK path rehearsed. LIMIT on UPDATE/DELETE (MySQL) adds a blast-radius cap; staging the change on a…
Read the full answer →SQL Fundamentals
18 questions across 2 topics — What SQL is, database thinking, sublanguages and the execution pipeline.
SELECT & Filtering
24 questions across 2 topics — Projection, execution order, WHERE depth, LIKE, IN, NULLs and sargability.
Modifying Data
10 questions across 1 topic — Guarded UPDATE/DELETE, upserts, bulk loads and lost-update defenses.
Aggregations & GROUP BY
14 questions across 1 topic — Aggregate functions, grouping, HAVING, pivots and top-N-per-group.
JOINs
14 questions across 1 topic — Every join type, ON vs WHERE, fan-out control and join performance.
Constraints & Keys
12 questions across 1 topic — Primary/foreign keys, uniqueness, checks and cascading actions.
Set Operations
10 questions across 1 topic — UNION, INTERSECT and EXCEPT — combining result sets correctly.
Subqueries, CTEs & Views
22 questions across 2 topics — Nesting, decorrelation, recursive CTEs and views as interfaces.
Window Functions
14 questions across 1 topic — Ranking, running totals, LAG/LEAD and frame semantics.
Indexes & Transactions
22 questions across 2 topics — B-trees, EXPLAIN, ACID, isolation levels and locking.
Design & Security
12 questions across 1 topic — Schema design, key strategies, migrations and injection defense.
Scenarios & Rapid Fire
20 questions across 2 topics — Production judgment calls, plus one-line revision for the night before.
Recommended resourcesAffiliate links · may earn us a commission