Skip to main content
Module 5 · Lesson 4 of 420/57 in the course~15 min
Module lessons (4/4)

UNION, INTERSECT, EXCEPT (and CROSS JOIN)

Lesson preview5 hands-on exercises readySQL Course · Module 5 — Advanced JOINs

Combine result sets using union, intersection, difference, and Cartesian products.

What you'll learn in this lesson

  • Combine results vertically with UNION, UNION ALL, INTERSECT and EXCEPT.
  • Make an informed choice between UNION (deduplicated) and UNION ALL (without deduplication, faster).
  • Understand when to generate all possible combinations with CROSS JOIN.

Overview

The JOIN combine columns horizontally by juxtaposing different tables. Set-theoretic operations (UNION, INTERSECT, EXCEPT, in contrast, stack or compare results vertically row against row — just like mathematical sets.

All set operations require: same number of columns in each SELECT, compatible types in the same order and ORDER BY written only once at the bottom. The final column names always come from the first SELECT.

Sections covered in this lesson

  1. 11. Mental Model: Vertical Sets vs Cartesian Product
  2. 22. Progressive & Annotated Examples
  3. 33. Interactive Lab: View the CROSS JOIN
  4. 44. Diagnostic Verification (Quiz)
  5. 55. Progressive Practical Laboratory
Pro Lesson · Module 5 — Advanced JOINs

Unlock "UNION, INTERSECT, EXCEPT (and CROSS JOIN)" and the full SQL Course curriculum

Combine result sets using union, intersection, difference, and Cartesian products.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in SQL Course plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.