access forms

Forum home » Delegate support and help forum » Microsoft Access Training and help » Access 2007 Forms

Access 2007 Forms

resolvedResolved · Low Priority · Version 2007

Barry has attended:
Access Intermediate course
Access Advanced course
Access VBA course

Access 2007 Forms

What is a union query for?

Edited on Mon 30 Mar 2009, 12:09

RE: Access 2007 Forms

Hi Barry

The UNION query allows you to combine the result sets of 2 or more "Select" queries. It removes duplicate rows between the various "Select" statements. To create a UNION quey you have to write the SQL String manually on the SQL Window. You cannot use the design view.

Each SQL statement within the UNION query must have the same number of fields in the result sets with similar data types.

The syntax for a UNION query is:

Select field1, field2, . field_n
From tables
UNION
Select field1, field2, . field_n
From tables;

For Example:

Select Customer_Id
From Customers
UNION
Select Customer_id
From Orders;


In this example, if a Customer_Id appeared in both the Customers and Orders table, it would appear once in your result set.

The UNION query removes duplicates.

Hope this helps

Carlos

Thu 9 Apr 2009: Automatically marked as resolved.


 

Access tip:

Deleting duplicate records from a table

You cannot delete records tables where there duplicate records. A way around this is to create a new table which wont hold the duplicates. and then deleting the old table.

1. Use a make-table query based on this table only. IMPORTANT - Ensure that you include all of the fields from your original table or you may loose data.

2. Open the query's property sheet by using VIEW, QUERY, PROPERTIES, and set the Unique Values property to Yes

3. Because you have selected the Unique Values to Yes when you run the query, Access creates a new table without duplicate records. You can now delete the old table and rename the new one.

View all Access hints and tips


Server loaded in 0.08 secs.