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

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.

EasyTechnical
70 practiced

Rewrite this old-style comma-separated join (FROM a, b WHERE a.id = b.a_id AND ...) into explicit JOIN ... ON syntax, and explain the practical reasons explicit joins are preferred in production code, including what silently goes wrong if someone forgets a WHERE condition in the old style.

EasyTechnical
62 practiced

What does a CROSS JOIN produce? Given two small tables like colors(color) and sizes(size), write the query that generates every combination for a product feed, and show a handful of example input/output rows.

EasyTechnical
77 practiced

Explain what INTERSECT and EXCEPT (or MINUS) do. Given two same-shaped snapshots of the same population (say two years of customer IDs), write queries that find customers present in both and customers present in one but not the other, and note how NULLs and duplicate rows affect the result.

EasyTechnical
70 practiced

Two tables you're joining share a column name (say both have an 'id' or 'created_at'). Show how to write the SELECT with table aliases and explicit column aliases so the result set has clear, unambiguous names, and explain what silently goes wrong for a downstream consumer (a BI tool, a script) if you don't.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.