Examples of union queries (MDB)

Microsoft Office Access 2003

The following union query selects all company names and cities from both the Suppliers and Customers tables, and sorts the data alphabetically by city.

SELECT [CompanyName], [City]
FROM [Suppliers]

UNION SELECT [CompanyName], [City]
FROM [Customers]
ORDER BY [City];
				

Show Renaming fields

The following union query renames the CompanyName field to "Supplier/Customer Name" in the query output.

SELECT [CompanyName] AS [Supplier/Customer Name], [City]
FROM [Suppliers]

UNION SELECT [CompanyName] AS [Supplier/Customer Name], [City]
FROM [Customers];
				

Show Returning duplicate records

The following union query uses the UNION ALL statement to retrieve all records, including duplicates.

SELECT [CompanyName], [City]
FROM [Suppliers]

UNION ALL SELECT [CompanyName], [City]
FROM [Customers];