Module lessons (4/4)
UNION, INTERSECT, EXCEPT (and CROSS JOIN)
Combine result sets using union, intersection, difference, and Cartesian products.
What you'll learn in this lesson
- Combine results vertically with
UNION,UNION ALL,INTERSECTandEXCEPT. - Make an informed choice between
UNION(deduplicated) andUNION 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
- 11. Mental Model: Vertical Sets vs Cartesian Product
- 22. Progressive & Annotated Examples
- 33. Interactive Lab: View the CROSS JOIN
- 44. Diagnostic Verification (Quiz)
- 55. Progressive Practical Laboratory
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.