O'Reilly logo

SQL: Visual QuickStart Guide by Chris Fehily

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Combining Rows with UNION

In the next three sections, I’ll cover the UNION, INTERSECT, and EXCEPT set operators, which combine the results of two SELECT statements into a single result. These operators can be mixed and chained to combine more than two tables. The UNION operator is supported widely; the other two operators, less so.

A UNION operation combines the results of two queries into a single result that comprises the rows returned by both queries. (This operation differs from a join, which combines columns from two tables.) A UNION expression removes duplicate rows from the result; a UNION ALL expression doesn’t remove duplicates.

Unions are simple, but they have some restrictions:

  • The SELECT-clause lists in the two queries must have ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required