Chapter 4: Querying Multiple Tables with Relational Operators

In This Chapter

arrow The UNION statement

arrow The INTERSECT statement

arrow The EXCEPT statement

arrow The JOIN statements

In Chapter 3 of this minibook, I show you how, by using nested queries, data can be drawn from multiple tables to answer a question that involves different ideas. Another way to collect information from multiple tables is to use the relational operators UNION, INTERSECT, EXCEPT, and JOIN. SQL’s UNION, INTERSECT, and EXCEPT operators are modeled after the union, intersect, and except operators of relational algebra. Each one performs a very specific combining operation on the data in two or more tables. The JOIN operator, on the other hand, is considerably more flexible. A number of different joins exist, and each performs a somewhat different operation. Depending on what you want in terms of information retrieved from multiple tables, one or another of the joins or the other relational operators is likely to give it to you. In this chapter, I show you each of SQL’s relational operators, cover how it works, and discuss what ...

Get SQL All-in-One For Dummies®, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.