Chapter 9. Set Operations
Recall from Chapter 2 that set theory is fundamental to the relational model. But whereas mathematical sets are unchanging, d.atabase sets are dynamic—they grow, shrink, and otherwise change over time. This chapter covers the following SQL set operators, which combine the results of two SELECT statements into one result:
UNIONreturns all the rows returned by both queries, with duplicates removed.INTERSECTreturns all rows common to both queries (that is, all distinct rows retrieved by both queries).EXCEPTreturns all rows from the first query without the rows that appear in the second query, with duplicates removed.
These set operations aren't joins, but you can mix and chain them to combine two or more tables.
This chapter ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access