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 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.