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.

MediumTechnical
60 practiced

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?

MediumTechnical
57 practiced

A query does customers LEFT JOIN orders and then filters in the WHERE clause on a column from the orders side. Explain why this silently turns the LEFT JOIN back into an INNER JOIN, show the corrected version that keeps customers with no matching orders, and describe how you'd write a quick check that catches this class of bug before it ships.

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.

MediumTechnical
70 practiced

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.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.