Ms Access 2010 tutorial:union query


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:

Ms Access union query book1

 Ms Access union query book2

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

Union

SELECT * FROM TblBook2

- Click Run to see the result

Ms Access union query 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.




Comments

jitendra kumar swain comment

 jitendra kumar swain

Access database is best of related report preparing.


2014-10-01



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.