SQL interviews test whether you can write correct, efficient queries and explain how relational databases work under the hood, not just memorize syntax. Expect questions spanning joins, aggregation, subqueries, window functions, indexing, and normalization, plus at least one live query-writing or debugging exercise. The strongest candidates can explain the tradeoffs behind a query, not just produce one that runs.
SQL interviews rarely fail candidates because they don't know what a SELECT statement does. They fail candidates because the questions are designed to expose how you think about data: whether you can reason about row multiplication, spot a filtering trap, or explain why a query is slow. This article walks through the core concept areas interviewers draw from, with worked examples and the pitfalls that trip up even experienced practitioners.
Every SQL interview is really testing five overlapping skills, even when the question looks like a simple syntax check.
Difficulty scales sharply by role. An analyst interview leans on joins, aggregation, and clean reporting logic. An engineer interview adds window functions, query optimization, and schema design trade-offs. A DBA interview pushes further into indexing strategy, isolation levels, and transaction behavior under concurrent load.
It's worth knowing where SQL sits relative to other tools you might be asked about, since interviewers sometimes probe judgment as much as syntax — the Python vs SQL debate comes up often when a role touches both data engineering and analysis.
Joins are the single most-tested SQL concept, and most mistakes come from not visualizing what happens to row counts.
Consider a customers table and an orders table. A LEFT JOIN from customers to orders returns one row per order, but customers with zero orders appear once with NULL order columns. If you then run COUNT(order_id), those NULL rows are correctly excluded — but COUNT(*) would count them, which is a frequent source of wrong totals.
UNION vs UNION ALL is another recurring question. UNION removes duplicate rows across the combined result sets, which means the database has to sort and compare every row. UNION ALL keeps everything, including duplicates, and is almost always faster. Default to UNION ALL unless you specifically need deduplication.
A join doesn't combine two tables — it asks a question about how two sets of facts relate, and the answer you get depends entirely on which rows you're willing to lose.
Start your SQL for Data journey — get a free 1:1 consultation.
What do these skills pay? Check the IT Salary Calculator → salaries by role, country and experience.
GROUP BY collapses rows that share a value in one or more columns, letting you apply aggregate functions like SUM, COUNT, AVG, MIN, and MAX to each group separately.
The classic trap interviewers set is WHERE vs HAVING. WHERE filters rows before grouping happens, so it can't reference an aggregate function. HAVING filters groups after aggregation, so it's the only place you can write something like HAVING SUM(amount) > 1000.
Another subtle trap: columns in the SELECT list that aren't wrapped in an aggregate function generally need to appear in the GROUP BY clause, or the query becomes ambiguous about which row's value to show.
Subqueries come in two flavors, and interviewers like to ask you to tell them apart. A non-correlated subquery runs once, independently of the outer query — for example, finding all orders above the overall average order value. A correlated subquery re-runs once per row of the outer query, referencing a value from that outer row each time, which makes it far more expensive on large tables.
Common Table Expressions (CTEs), written with a WITH clause, don't change what's computationally possible but dramatically improve readability. Breaking a complex query into named, sequential steps makes it easier to debug and easier for an interviewer to follow your reasoning aloud.
Window functions are where mid-to-senior interviews separate strong candidates from average ones.
The key conceptual difference from GROUP BY: window functions let you compute aggregates while still returning every individual row, which is exactly what reporting queries usually need.
An index is a separate data structure, usually a B-tree, that lets the database locate rows without scanning the whole table. It speeds up reads on the indexed column but adds overhead to every write, since the index has to be updated too.
Reading an execution plan (via EXPLAIN or EXPLAIN ANALYZE) is a skill interviewers increasingly test directly. Look for full table scans on large tables, nested loop joins where a hash join would be cheaper, and steps with unexpectedly high estimated row counts — these are usually where a query's time is actually being spent.
When diagnosing a slow query, start by checking whether the WHERE and JOIN columns are indexed, then look for functions wrapped around indexed columns, since that usually prevents the index from being used at all.
ACID properties — Atomicity, Consistency, Isolation, Durability — describe what a transaction guarantees. Interviewers often ask you to explain what breaks if one of these is weakened, especially Isolation.
Normalization questions test whether you understand why redundancy causes update anomalies. First normal form eliminates repeating groups, second normal form removes partial dependencies on a composite key, and third normal form removes transitive dependencies on non-key columns. Interviewers also like asking when it makes sense to denormalize deliberately — typically for read-heavy reporting workloads where join cost outweighs redundancy risk, a trade-off that comes up constantly when designing schemas for cloud database services.
Constraint design is another integrity check: primary keys enforce uniqueness, foreign keys enforce referential integrity, and NOT NULL or CHECK constraints push validation down into the database rather than leaving it entirely to application code.
Live SQL problems test process as much as output. The strongest candidates work through a consistent sequence rather than jumping straight to code.
If a problem involves especially large datasets or distributed processing, it's reasonable to mention how the approach would differ at scale — this is also where familiarity with Apache Spark architecture can come up if the conversation shifts from single-database SQL to distributed query engines.
Many of these mistakes come from treating SQL as purely declarative syntax rather than as a tool for reasoning about sets. Newer data roles layer additional concepts on top of this foundation — similarity search over embeddings, for instance, has pushed vector search databases into interviews for roles touching machine learning pipelines, even when the core job is still SQL-heavy. Building fluency across both relational and newer data paradigms is part of why broader programmes, such as a Data Science with Python programme, pair SQL fundamentals with the surrounding ecosystem rather than teaching it in isolation.
WHERE filters individual rows before any grouping happens, while HAVING filters groups after GROUP BY has been applied. You can use aggregate functions like COUNT() or SUM() in HAVING but not in WHERE. A common mistake is trying to filter on an aggregate in WHERE, which throws an error.
A primary key uniquely identifies each row and cannot contain NULLs, and a table can only have one. A unique key also enforces uniqueness but allows a single NULL value (in most databases) and a table can have several unique keys. Both create an index automatically in most systems.
Group by the columns that define a duplicate and use HAVING COUNT(*) > 1 to surface the offending groups. For row-level duplicate removal, pair ROW_NUMBER() OVER (PARTITION BY ... ORDER BY ...) with a filter to keep only the first occurrence. This approach also works for deciding which duplicate to keep based on a tiebreaker column.
ROW_NUMBER assigns a unique sequential number to every row regardless of ties. RANK gives tied rows the same rank but skips subsequent numbers, while DENSE_RANK gives tied rows the same rank without skipping. Interviewers use this to check if you understand how ties are handled, not just that you know the function names.
Start by reading the execution plan to find full table scans, missing index usage, or expensive joins/sorts. Then check if an index on the filter or join columns would help, whether the query is pulling more columns or rows than needed, and whether a subquery can be rewritten as a join or CTE. Always validate the fix by comparing before/after plans, not just execution time.
UNION combines result sets and removes duplicate rows, which requires an internal sort or hash step and costs more performance. UNION ALL combines result sets and keeps all rows including duplicates, making it faster when you know duplicates aren't a concern. Default to UNION ALL unless you specifically need deduplication.
Browse our upcoming batches — live, instructor-led, delivered on Orbit.