O'Reilly logo

Microsoft® SQL Server™ 2000 Programming by Example by Carlos Eduardo Rojas, Fernando G. Guerrero

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

The UNION Operator

UNION is an operator used to combine two or more SELECT statements and generate one result set. These SELECT statements must meet some conditions, such as the following:

  • They must have the same number of columns. You can work around this restriction if you use constants in the SELECT statement with fewer columns, as shown in Listing 5.21.

Code Listing 5.21. Using a UNION Operator with Constants in the SELECT Statements
					 -- A constant has to be used in the second SELECT statement -- because Shippers doesn't have a contactname column USE Northwind SELECT companyname, contactname FROM Suppliers WHERE country = 'USA' UNION SELECT ...

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