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.

HardTechnical
74 practiced

Given two time ranges per entity (for example user sessions, or active subscription periods that can pause and resume), write a query that detects when two ranges for the same entity overlap, being explicit about whether touching endpoints count as an overlap and how you handle a still-open range (no end timestamp yet). Make sure a pair isn't reported twice and an entity isn't compared to itself.

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
58 practiced

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.

HardTechnical
62 practiced

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.

HardTechnical
124 practiced

A join chain across three source tables is returning noticeably fewer rows than you expected, and nothing obviously errored. Walk through how you'd systematically track down where the rows are being lost. For each hypothesis you consider, describe the specific SQL check you'd run and what a bad result would tell you.

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.