Sometimes you need to combine information of a similar type from more than one table. A classic example of this is merging two or more mailing lists prior to a mailing campaign. Depending on the purpose of a particular mailing, you might want to send letters to any of these combinations of people: Everyone in both lists (while avoiding sending two letters to someone who happens to be in both lists)
- Only those people who are in both lists
- Those people in only one of the lists
These three combinations of lists are known in Oracle as UNION, INTERSECT, and MINUS. In the following examples, you will see how to use these three clauses to manage the results of multiple queries.
The examples will compare the books on hand (BOOKSHELF) with those on order (BOOK_ORDER).
To see all the books, UNION the two tables. To reduce the size of the output, only the BOOKSHELF entries from the first half of the alphabet are selected.
The following select returns 14 rows: