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
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.

EasyTechnical
57 practiced

What does JOIN ... USING(column) do differently from JOIN ... ON a.column = b.column, particularly for the shared column in the result set and how you reference it afterward in SELECT or ORDER BY? Show a short example, and note where dialect support or behavior differs.

MediumTechnical
66 practiced

Why does join order matter to a cost-based optimizer, and how does it decide the order? Contrast a cost-based approach with a purely heuristic one, and give a concrete example of a multi-table join where reordering changes the size of an intermediate result.

HardTechnical
56 practiced

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.

MediumTechnical
76 practiced

Write a query that performs a FULL OUTER JOIN of two same-shaped tables (say two systems' daily revenue figures) and produces one reconciled row per key with both sides' values, a delta, and a status column ('match' / 'mismatch' / 'only in left' / 'only in right'). Then explain how you'd emulate a FULL OUTER JOIN in a dialect that doesn't support it, and how the same pattern extends to reconciling three or more sources at once.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.