Describe set operations UNION, INTERSECT, and EXCEPT

SQL
Medium
124.7K views

This tests advanced set logic in SQL. It is useful for merging and comparing datasets.

Why Interviewers Ask This

Set operations are powerful for combining and comparing results. Interviewers ask this to see if candidates know how to merge, find commonalities, or find differences between datasets efficiently.

How to Answer This Question

Define UNION as combining and removing duplicates. Define INTERSECT as finding common rows. Define EXCEPT as finding rows in first but not second. Mention compatibility requirements (same columns).

Key Points to Cover

  • UNION merges and deduplicates
  • INTERSECT finds common rows
  • EXCEPT finds differences
  • Requires compatible columns

Sample Answer

UNION, INTERSECT, and EXCEPT are set operations that combine results from two queries. UNION returns the distinct union, removing duplicates. INTERSECT returns only rows present in both result sets. EXCEPT returns rows f…

Common Mistakes to Avoid

  • Ignoring column compatibility
  • Confusing INTERSECT with JOIN
  • Forgetting UNION removes duplicates

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 84 SQL questions