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.

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

What happens if you put an ORDER BY and LIMIT inside each branch of a UNION, then union those branches together? Explain the standard SQL behavior here and how it differs from applying ORDER BY/LIMIT to the final unioned result, and show the correct way to get 'top M rows per branch' out of a unioned query.

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.

HardTechnical
69 practiced

You're joining a fact row to the dimension attribute that was valid at the fact's own point in time, for example the price, exchange rate, sales territory, or subscription status that was in effect on a given date, where the dimension table stores effective date ranges. Write a join that picks the single correct valid row (using non-equi conditions on the date range) and handle both an open-ended range (NULL end date meaning 'still current') and the case where two candidate ranges legitimately overlap and you need a deterministic priority rule to pick one.

MediumTechnical
113 practiced

You need to detect which rows changed between two full snapshots of the same table (an old and a new load) so you can do an incremental, idempotent load rather than reprocessing everything. Write a query using EXCEPT (or an EXCEPT-equivalent) to find the rows present in the new snapshot but not the old one, with a null-safe comparison strategy, and explain why this supports idempotent loads.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.