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.

MediumTechnical
57 practiced

A query does customers LEFT JOIN orders and then filters in the WHERE clause on a column from the orders side. Explain why this silently turns the LEFT JOIN back into an INNER JOIN, show the corrected version that keeps customers with no matching orders, and describe how you'd write a quick check that catches this class of bug before it ships.

MediumTechnical
83 practiced

Given a referrals table (referrer_id, referred_id, created_at), write a self-join query that finds pairs of people who referred each other (mutual referrals). Discuss what makes this self-join different from a hierarchy self-join, and what indexing you'd want on a large table for this pattern.

MediumTechnical
78 practiced

How does NULL behave in a join's equality condition, and separately in UNION/INTERSECT/EXCEPT comparisons? Build a small two-table example where a NULL join key causes a row to silently drop out of an INNER JOIN, show how a LEFT JOIN's NULLs can distort a downstream SUM or AVG if you're not careful, and demonstrate how COALESCE can defend against both.

EasyTechnical
76 practiced

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?

EasyTechnical
77 practiced

Explain what INTERSECT and EXCEPT (or MINUS) do. Given two same-shaped snapshots of the same population (say two years of customer IDs), write queries that find customers present in both and customers present in one but not the other, and note how NULLs and duplicate rows affect the result.

Unlock Full Question Bank

Get access to all 35 SQL Joins and Set Operations interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.