O'Reilly logo

Practical SQL Handbook, The: Using SQL Variants, Fourth Edition by Sandra L. Emerson, Marcy Darnovsky, Judith S. Bowman

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

UNION

Although UNION isn't a join, it is a way of combining data from multiple tables into one display. UNION is useful when you want to see similar data from two or more tables in one display. The simplified syntax is this:

select_statement
UNION
select_statement

Following is a query that will give you a list of all the authors and editors who live in Oakland or Berkeley:

SQL
select au_fname, au_lname, city
from authors
where city in ('Oakland', 'Berkeley')
union
select ed_fname, ed_lname, city
from editors
where city in ('Oakland', 'Berkeley')

Notice that the two SELECT lists contain the same number of items and the datatypes are compatible. Check your documentation for specifics on what datatype combinations you can use.

When you examine ...

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