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.
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.
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.
Two tables you need to join don't line up cleanly on a plain equality: one side stores a timestamp and the other a truncated date, or the identifiers differ in case, formatting, or timezone. Show how you'd write a correct join across the mismatch (using an expression on the join key, or normalizing beforehand), and explain the performance cost of joining on a transformed expression versus normalizing the data first.
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?
Given an employees table that references itself for a manager relationship (employee_id, name, manager_id), write a query that returns each employee alongside their manager's name, showing NULL (or an explicit 'no manager') for anyone at the top of the org. Explain why a self-join is the natural tool here, and how you'd extend the same pattern one more level up (manager's manager) or decide you need a recursive CTE instead.
Unlock Full Question Bank
Get access to all 41 SQL Joins and Set Operations interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.