SQL Joins and Set Operations Questions
Combining data across multiple tables using inner, outer, cross, and self joins, plus set operations (UNION, INTERSECT, EXCEPT). Covers join-key selection, fan-out and row-multiplication pitfalls, merge strategies, and integrating data from disparate sources. A high-frequency interview surface for anyone who queries relational data.
Walk me through INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN, and CROSS JOIN: what each one returns, how row counts change relative to the inputs, and how unmatched rows show up as NULLs. Ground it with a short two-table example (say customers and orders).
A multi-table query is returning a far larger result set than expected. Walk through how you'd confirm it's an accidental Cartesian product (missing or wrong join predicate) rather than a genuine data issue, using row-count checks and progressive query construction, then show the corrected query. What would you add to code review or CI to catch this class of bug before it ships?
Rewrite a per-row correlated scalar subquery (one that runs once per outer row to compute a count or sum) into an equivalent JOIN with an aggregation, and explain why the rewritten version is usually faster on large tables.
Given a chain of one-to-many relationships (A links to many B, each B links to many C), write a query that returns each A row with the correct COUNT(DISTINCT ...) of related C rows, even when some intermediate B rows are missing entirely. Explain what would go wrong with a naive join here.
Given three tables joined as A LEFT JOIN B LEFT JOIN C, explain how changing the order in which the outer joins are evaluated can change which rows survive in the final result, not just how fast the query runs. Construct a small example that demonstrates it, and show how you'd restructure the query (e.g. via a derived table or CTE) to get the semantics you actually want.
Unlock Full Question Bank
Get access to all 33 SQL Joins and Set Operations interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.