Skip to content
Advertisement

Access SQL: Update list with Max() and Min() values not possible

I’ve a list of dates: list_of_dates.

I want to find the max and min values of each number with this code (#1).

It works how it should, and therefore I get the table MinMax

Now I want to update a other list (list_of_things) with these newly acquired values (#2).

However, it is not possible. I assume it’s due to DISTINCT and the fact that I always get two rows per number, each with the min and max values. Therefore an update is not possible. Unfortunately I don’t know any other way.

list_of_dates MinMax dates sorted

Advertisement

Answer

No part of an MS Access update query can contain aggregation, else the resulting recordset becomes ‘not updateable’.

In your case, the use of the min & max aggregate functions within the MinMax subquery cause the final update query to become not updateable.

Whilst it is not always advisable to store aggregated data (in favour of generating an output from transactional data using queries), if you really need to do this, here are two possible methods:

1. Using a Temporary Table to store the Aggregated Result

Run a select into query such as the following:

To generate a temporary table called temptable, then run the following update query which sources date from this temporary table:

2. Use Domain Aggregate Functions

Since domain aggregate functions (dcount, dsum, dmin, dmax etc.) are evaluated separately from the evaluation of the query, they do not break the updateable nature of a query.

As such, you might consider using a query such as:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement