Previous chapters looked at how data can be retrieved from multiple tables using joins. Data can also be retrieved from multiple tables using set operations. In this chapter we will look at the different set operations available in SQL.
A set is a collection of objects. In relational databases, a table is a set of rows. Elements in a set are not ordered. Whereas elements in mathematical sets do not have duplicate entries, duplicate rows may occur in relational tables unless they are explicitly disallowed.
Three set operations are used in SQL: UNION, INTERSECT, and MINUS (set difference). A binary union is a set operation on two sets where the result contains all the unique elements of both sets. A binary intersection ...