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.
What's the difference between an equi-join and a non-equi join? Give a concrete example where a non-equi join is the right tool, for example matching a transaction amount to the pricing tier it falls into, and talk through the indexing and performance considerations that change once you move off plain equality.
When would you restructure a deeply nested, hard-to-review multi-join query into a series of CTEs instead of leaving it as nested subqueries? Take a query chaining several joins and rewrite it as staged CTEs, explaining how you decided where to break it up and any performance caveats worth knowing about.
Explain semi-join and anti-join as concepts distinct from a regular INNER or LEFT JOIN: what question each one answers and why. Then write a semi-join with EXISTS to check whether a customer has any qualifying transaction, and explain why this can outperform (and avoid duplicate rows compared to) an INNER JOIN followed by DISTINCT.
You need to combine rows from two or more sources whose schemas don't quite match (different column names, or one source missing a column the others have). Write a UNION ALL that normalizes the columns first, and explain the choices you made for any column that only exists on one side.
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).
Unlock Full Question Bank
Get access to all 45 SQL Joins and Set Operations interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.