Others

Fix Access UNION Query Aggregate Function Error with Long Text

Muhammad TalhaMuhammad Talha Nov 2, 2026 868 views

Question details

The user is experiencing an aggregate-function error in an Access UNION query when attempting to use the 'Last' function to prevent a Long Text field from being truncated.

How to Fix Access UNION Query Aggregate Function Error with Long Text
Product
Microsoft Access
Device & OS
not provided
Scenario
Combining records from multiple tables with similar structures (e.g., Cashier and Kluis entities) into a single result set without losing data in Long Text fields.
Observed behavior
Using the 'Last' aggregate function on a Long Text field within the UNION query results in an error or undefined behavior, as 'Last' is unreliable without an explicit ordering clause.
Before you start

Verify the primary keys or unique identifiers in your source tables (like Cashier and Kluis), as you will need them to create reliable joins in subsequent queries.

Solution 1Recommended

Exclude Long Text from the UNION Query and Join Later

The most reliable method to prevent Long Text truncation and avoid aggregate function errors is to perform the UNION operation on standard fields first, then join the results back to the original tables.

Microsoft Access automatically treats Long Text fields as standard Short Text (truncating at 255 characters) when processing UNION queries to remove duplicates. Bypassing the Long Text field during the UNION phase prevents this limitation entirely.

1
Create a base UNION query

Open SQL View and write your UNION query selecting only the primary key identifiers and any other required standard fields from your tables (e.g., Cashier and Kluis). Completely omit the Long Text field.

2
Save the UNION query

Save this initial query with a recognizable name, such as 'qryBaseUnion'.

3
Create a new Select query

Go to the Create tab and open Query Design. Add your newly saved 'qryBaseUnion' along with the original tables that contain the Long Text fields.

4
Join and retrieve Long Text

Create a join between the primary keys in 'qryBaseUnion' and the original tables. Add the Long Text field to your query grid from the original tables, then run the query.

Exclude Long Text from the UNION Query and Join Later
Best Practice: This method not only prevents text truncation but also significantly improves query execution speed by reducing the amount of data processed during the UNION operation.
Free Microsoft Office alternative

Looking for a Lightweight Alternative to Microsoft Office?

While Microsoft Access handles highly complex database tasks, WPS Office is an exceptional free alternative for managing your daily document, spreadsheet, and presentation needs. It is lightweight, fast, and fully compatible with mainstream Office formats.

  1. 1. Download WPS Office: Visit the official WPS website to download the free installation package for your operating system.
  2. 2. Install and Set Up: Run the installer and follow the quick prompts. WPS Office is lightweight and installs in minutes.
  3. 3. Open Your Files Seamlessly: Double-click any existing Microsoft Office document to open it in WPS Office without losing any formatting.
Free and lightweight office suite with rapid startupSeamless compatibility with Microsoft Word, Excel, and PowerPoint formatsFamiliar user interface requiring zero learning curveBuilt-in PDF editing, conversion, and annotation tools
microsoft office alternative - wps office

Frequently Asked Questions

Why does Microsoft Access truncate Long Text fields to 255 characters in UNION queries?

A standard UNION query automatically groups records to eliminate duplicates. Because Access cannot group on Long Text (formerly Memo) fields, it converts them to Short Text and cuts them off at 255 characters to perform the grouping operation.

What is the difference between UNION and UNION ALL?

UNION combines the results of two queries and removes duplicate rows, which requires data grouping. UNION ALL simply appends the results together without checking for duplicates, meaning it is faster and does not trigger Long Text truncation.

Why does the 'Last' aggregate function return the wrong data?

In Microsoft Access, 'Last' refers to the chronological sequence in which records were physically entered into the table, not the alphabetic or numeric order. Unless an explicit ORDER BY clause is applied, 'Last' will return unpredictable results.