InterviewStack.io LogoInterviewStack.io

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

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.

MediumTechnical
74 practiced

You need one canonical row per key from a table containing duplicates (keep the most recent by a timestamp column), and you're told to do it with a join-based approach rather than a window function. Write that query, and discuss the trade-offs against a ROW_NUMBER()-based approach.

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.

HardTechnical
75 practiced

A distributed join is stalling because one join key is far more frequent than the others (data skew), and a single task or partition is doing most of the work. Explain how you would confirm skew is the cause from the execution metrics, and walk through the salting technique end-to-end, including how you would remove the salt again for a correct final aggregate.

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.

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.