Our last method of combining queries is through the use of set operators. While set operators are generally not used by SQL programmers on a day-to-day basis, when the situation calls for them, they can be extremely useful. Before we examine SQL set operators in detail, it is advantageous for us to briefly review mathematical set theory to see how they work.
If you think back to your school math classes, you may remember learning about a topic known as set theory. Set theory is the branch of mathematics that involves the study of collections of objects, or sets. Because databases deal with collections of data, set theory is relevant to the more theoretical aspects of relational database theory. However, for our purposes, an extensive review is not necessary. It is enough to learn the basic ideas and terminology of set theory as it applies to SQL.
Set theory is used to describe the interaction of groups of objects or lack thereof. The primary...