What are set operations like UNION, INTERSECT, and EXCEPT?

SQL
Medium
57.8K views

This question tests your knowledge of combining result sets beyond just appending. It evaluates understanding of mathematical set theory applied to SQL.

Why Interviewers Ask This

Set operations allow powerful data manipulation. Interviewers ask this to see if you can merge, compare, or exclude datasets efficiently. These operations are fundamental for complex reporting requirements involving multiple sources.

How to Answer This Question

Define UNION as merging distinct rows from two queries. Define INTERSECT as returning only rows present in both queries. Define EXCEPT (or MINUS) as returning rows in the first query but not the second. Emphasize that column counts and types must match.

Key Points to Cover

  • UNION merges and deduplicates
  • INTERSECT finds common rows
  • EXCEPT finds differences

Sample Answer

UNION combines results from two queries and removes duplicates. INTERSECT returns only the rows that appear in both result sets. EXCEPT returns rows from the first query that are not found in the second. All these operat…

Common Mistakes to Avoid

  • Forgetting that columns must match
  • Confusing INTERSECT with INNER JOIN
  • Not realizing UNION removes duplicates by default

Sound confident on this question in 5 minutes

Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.

Try it free

Related Interview Questions

Browse all 101 SQL questions