473,408 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

min/max values from one table to another

I'm trying to update a field in one table with the minimum values of
the field in another table. The two tables are linked via a common
field. I want to populate a date field in one table with the earliest
date in another table where the linking fields values are equal. I
set up a query with the two tables, made sure the common fields were
linked, set the query as an "update" query, placed the field and table
I want to update in the query grid and set the 'update to' value to
"Min(firsttable.datefield)". When I run the query, I get the
following error:
"You tried to execute a query that does not include the specified
expression 'EarliestDate' as part of an aggregate function"

Any ideas how to do this? Thanks.

Doug
Nov 12 '05 #1
2 12380
Do*********@nps.gov (Wilder) wrote in
news:b2**************************@posting.google.c om:
I'm trying to update a field in one table with the minimum
values of the field in another table. The two tables are
linked via a common field. I want to populate a date field in
one table with the earliest date in another table where the
linking fields values are equal. I set up a query with the
two tables, made sure the common fields were linked, set the
query as an "update" query, placed the field and table I want
to update in the query grid and set the 'update to' value to
"Min(firsttable.datefield)". When I run the query, I get the
following error:
"You tried to execute a query that does not include the
specified expression 'EarliestDate' as part of an aggregate
function"

Any ideas how to do this? Thanks.


you can use a query just like a table in building another query.

Build a proper aggregate query first, then build the update query
using the aggregate query and the second table.

aggregate Query:
SELECT firsttable.[linking field], min(firsttable.groupfield as md
from firsttable GROUP BY firsttable.[linking field]

The better way is to just create a select query using the second
table and the aggregate query because you really don't need the
duplicate field.

SELECT query
Select secondtable.[linking field], [aggregate query].md from
secondtable inner join [aggregate query] on secondtable.[linking
field] = [aggregate query].[linking field]

If you insist on having the field in secondtable, then convert the
select query above to an update query.

UPDATE secondtable inner join [aggregate query] on
secondtable.[linking field] = [aggregate query].[linking field] SET
mydatefield = [aggregate query].md

Nov 12 '05 #2
Thanks, this works great! I did it first for the latest dates and now
I'm trying to get the earliest dates into the table but am having
difficulties. I reran the query to get the earliest dates instead of
the latest and then tried making an update query to add these to the
table. In the update query, I added the table and the query and
linked them on the common field. Then in the grid I added the field I
want to contain the values and set its "update to" value to
[qryDates].[earliest]. Here's the SQL:

UPDATE tblPacks INNER JOIN qryMinMaxDates ON tblPacks.PackID =
qryMinMaxDates.ASSO SET tblPacks.EarliestObservationDate =
[qryMinMaxDates].[earliest];

When I run this I get the error:
Operation must use an updateable query

So how do I add the earliest dates to the table? Thanks again for
your expert help!

Doug Wilder
National Park Service
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Berend | last post by:
I am trying to pass multi values into a where clause with an in clause in a store procedure to use in a Crystal report. This can change depending on the user. Maybe there is another way to pass...
26
by: Agoston Bejo | last post by:
I want to enforce such a constraint on a column that would ensure that the values be all unique, but this wouldn't apply to NULL values. (I.e. there may be more than one NULL value in the column.)...
1
by: Programmer | last post by:
Hi All Here is my problem I'm using a SQLDataAdapter and DataSet I use the method FillSchema(myDataset, SchemaType.Source) The problem is that when i Check the default Values of the Dataset...
5
by: kevinjouco | last post by:
Hello Have searched the group for a solution to the following problem without success: Table 1 has Ref No (No Duplicates) & Min Max Value Fields ie Ref No 1 Min 1 Max 10 Ref No 2 Min 11 Max...
8
by: Chris A via AccessMonster.com | last post by:
I have an interesting problem that I have yet to come accross that I can't change data structure on because it is an export from filemaker I am reformatting for another dept. anyway. I have a table...
4
by: J | last post by:
I am editing a pre-existing view. This view is already bringing data from 40+ tables so I am to modify it without screwing with anything else that is already in there. I need to (left) join it...
1
by: socc16e | last post by:
I have an excel sheet that I have imported into SQL 2000 and I need to match the values in one to the values in another and have them output the matching codes to a separate table or file. After...
0
by: Mark C. Stock | last post by:
"Mark C. Stock" <mcstockX@Xenquery .comwrote in message news:... | | "Berend" <Berend.Brinkhuis@evatone.comwrote in message | news:bdd9ac20.0401271301.22cdb65e@posting.google.com... | | I am...
2
dlite922
by: dlite922 | last post by:
I have a permission table that gives a userID permission to a module and the any actions within that module. What I want to do is duplicate his permissions to another user. Permission table...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.