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.
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?
A multi-table query is returning a far larger result set than expected. Walk through how you'd confirm it's an accidental Cartesian product (missing or wrong join predicate) rather than a genuine data issue, using row-count checks and progressive query construction, then show the corrected query. What would you add to code review or CI to catch this class of bug before it ships?
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.
You need a report row for every combination of two dimensions even when there's no matching activity, for example every date in a month against every category, showing zero where nothing happened. Write the query and explain why CROSS JOIN (rather than an ordinary join) is the right tool here, and how you'd guard against it silently blowing up if one of the input sets grows.
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.
Unlock Full Question Bank
Get access to all 42 SQL Joins and Set Operations interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.