Ms Access 2010 tutorial:union query
XV. Union Query A union query is a type of the select query that allows you to combine records from different tables or queries. To combine records from tables or queries by using the union query, you need to know its rule-- the tables or queries that you want to combine must have the same number of columns, unless the union query cannot execute.
For example, you have two tables TblBook1 and TblBook2. The two tables have the same number of columns, and field names . These tables are used to store books' information. You ask your friend to help you enter the books' information. You enter data into TblBook1 and your friend enters data into TblBook2. These two tables contain the data as figure below:
After you and your friend finish the work, you want to combine these data into one table. To do that you need to create a union query. To create the union query follow the steps below:
- Click Create tab
- Click Query Design, in Queries group
- Click Close button of Show Table Dialog box
- Click Union, in Query Type group, next to Results group
The Union query window open and then type the following statements:
SELECT * FROM TblBook1
SELECT * FROM TblBook2
- Click Run to see the result
TblBook1 and TblBook2 have the duplicate records (B005,B006), but when you use UNION operator, it combines the record without duplicates. That's why you see the result showing only unique records rom B001 to B010.
Note: You can combine records from more than tables or queries. The fields of combined tables or queries should have the same data types, otherwise the fields' data types will change.