Chapter 4

Querying Multiple Tables with Relational Operators


Bullet The UNION statement

Bullet The INTERSECT statement

Bullet The EXCEPT statement

Bullet 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, 3rd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.