intermediate~2h

Set Operators — UNION, INTERSECT, EXCEPT/MINUS

SQL's set operators combine the results of two queries by set logic rather than by joining columns — the right tool whenever the question is really "which rows are in either, both, or only one of these two result sets."

Learning objectives

  • State precisely what UNION, UNION ALL, INTERSECT, and EXCEPT each keep and discard.
  • Explain why UNION ALL is cheaper than UNION, in terms of what work the database skips.
  • Recognize when a set operator is the right tool versus when a JOIN actually answers the question.

This is a Pro chapter

Sign in, then upgrade to Pro or Power to unlock this and the full Databases Mastery library.

Set Operators — UNION, INTERSECT, EXCEPT/MINUS

Next Step

Continue to Advanced SQL — Stored Procedures, Functions, Triggers & Sequences← Back to all SQL chapters