1. Home
  2. Computing & Technology
  3. Databases
Mike Chapple
Mike's Databases Blog

By Mike Chapple, About.com Guide to Databases

Combining Query Results with SQL's UNION Statement

Sunday April 26, 2009
SQL’s UNION command allows you to combine the results of two or more database queries that are not necessarily linked through a database relationship. For example, imagine that you have a school database and wish to use it to create a master contact list for all students, faculty and staff. Looking at your database, you discover that the records corresponding to each of these constituencies appears in separate database tables.

Your first instinct might be to export the data from each table into a spreadsheet and combine the information there. However, you can combine these records within your database by writing separate queries for each constituency and combining the results of those queries with the UNION statement.

Read the full article: Combining Query Results with SQL's UNION Statement
Comments
April 26, 2009 at 3:52 pm
(1) Richard Rost says:

Mike, excellent tutorial on Union Queries. It’s interesting to note also that Access doesn’t allow you to build Union Queries with the graphical query designer. If you don’t know SQL, you simply cannot create one.

Richard Rost
AccessLearningZone.com

October 26, 2009 at 2:11 pm
(2) erich says:

How do we combine UNION with WHERE statement? I have more than 3 separate tables using UNION something like: $sql = $sql_a . ‘ UNION ALL ‘ . $sql_b . ‘ UNION ALL ‘ . $sql_c;
Tried using WHERE after this statement seem doesn’t work. is it possible?

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore Databases
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Databases

©2009 About.com, a part of The New York Times Company.

All rights reserved.