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'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.
What's the difference between UNION and UNION ALL? Given two same-shaped monthly tables that may contain overlapping rows, write both versions of combining them, and explain when you'd reach for UNION ALL by default and what it costs you to add the dedup pass back in.
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.
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 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 35 SQL Joins and Set Operations interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.