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.
After joining a fact table through a one-to-many (or many-to-many) relationship, you're seeing inflated aggregate totals from duplicated detail rows. Compare at least two concrete fixes: pre-aggregating before the join versus deduplicating the many side with a canonical-row rule, and explain why reaching for a bare DISTINCT on the final result is usually a band-aid that hides the real problem rather than fixing it.
Explain what a RIGHT JOIN does, then rewrite a RIGHT JOIN query as an equivalent LEFT JOIN by swapping the table order. Why do many teams avoid RIGHT JOIN in their codebase even though it's standard SQL?
A LEFT JOIN is returning more rows than the left-hand table has, or a dashboard's totals look inflated after a join was added. Walk through a step-by-step investigation: what counts and EXISTS checks you'd run first, how you'd confirm which specific join is the culprit, and what you'd check when the culprit turns out to be the join KEY itself (wrong column, or a granularity mismatch) rather than the join type.
EXCEPT and INTERSECT require matching columns on both sides, but engines differ in how they treat NULLs in the compared columns and in dialect-specific behavior (MINUS vs EXCEPT, availability). Given two tables with NULLs in a key column, show a case where the result is not what a newcomer would expect, and how to explicitly include or exclude NULL rows.
Same underlying question, three different tools: given two point-in-time snapshots of the same population, write it (a) as a LEFT JOIN anti-join, (b) as NOT EXISTS, and (c) using EXCEPT. Compare correctness (especially around NULLs and duplicate rows) and typical performance across these three, and say which you'd default to.
Unlock Full Question Bank
Get access to all 42 SQL Joins and Set Operations interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.