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.
Optimizer hints (forcing a join order, an index, or a specific join algorithm) exist in most major databases under different names. When is reaching for a hint the right call for a critical query, and what maintenance risk does relying on hints introduce as the underlying data or version changes? Give the guardrails you would put in place before shipping one.
You're joining on a composite key, but for some rows one part of the key is NULL and the business rule says that NULL should act as a wildcard matching any value on the other side, not as 'no match'. Write the join that implements this, and separately explain why casually treating NULL as a literal sentinel value (e.g. coalescing it to a string like 'NULL') is dangerous when that string could itself be a legitimate value in the data.
Write a query that performs a FULL OUTER JOIN of two same-shaped tables (say two systems' daily revenue figures) and produces one reconciled row per key with both sides' values, a delta, and a status column ('match' / 'mismatch' / 'only in left' / 'only in right'). Then explain how you'd emulate a FULL OUTER JOIN in a dialect that doesn't support it, and how the same pattern extends to reconciling three or more sources at once.
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.
Walk me through INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN, and CROSS JOIN: what each one returns, how row counts change relative to the inputs, and how unmatched rows show up as NULLs. Ground it with a short two-table example (say customers and orders).
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.