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.
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.
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 employees(employee_id, name, dept_id) and departments(dept_id, dept_name), write a query that returns each employee's name and their department name, but only for employees who currently have a department assigned. Explain why the join you chose is the right one, and what happens to employees with no department.
Joins combine tables horizontally (adding columns); set operations combine result sets vertically (stacking or comparing rows). Give two concrete examples where the right tool is a set operation and two where it's a join, and explain what goes wrong with duplicate and NULL handling if you reach for the wrong shape.
Explain what a LATERAL join (or CROSS APPLY) does that a plain JOIN can't, then use it to attach each parent row's most recent (or top-N) related child rows, for example each customer's most recent invoice or each order's top 3 shipments. Compare it to solving the same problem with a window function instead, and say when you'd reach for each.
Unlock Full Question Bank
Get access to all 45 SQL Joins and Set Operations interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.