Set Operations

You can think of joins as horizontal operations between tables, generating a virtual table that contains columns from both tables. This section covers vertical operations between tables, including UNION, EXCEPT, and INTERSECT. Any mention of set operations in this section refers to these vertical operations.

A set operation operates on two input tables, each resulting from a query specification. For simplicity’s sake, I’ll just use the term inputs in this section to describe the input tables of the set operations.

UNION returns the unified set of rows from both inputs, EXCEPT returns the rows that appear in the first input but not the second, and INTERSECT returns rows that are common to both inputs.

ANSI SQL:1999 defines native operators ...

Get Inside Microsoft® SQL Server® 2008: T-SQL Querying now with O’Reilly online learning.

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