473,385 Members | 1,973 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,385 software developers and data experts.

Records Based on Recent Date

Hello Everyone,

I'm helping out a non-profit school with their database. They would like to
know the last gift made by each donor, the donor name, and the gift amount.

I built a query based on two tables. The donor name is from the first table
[Gen_info]. The gift [Date] and [Gift] are in the second table [Gift
Detail].

The query works except for one problem. It will return the proper number of
records with the most recent gift date as long as I don't add the [gift]
field (which is the dollar amount). As soon as I add the [gift] field it
gives me all the gifts for each donor instead of the most recent. The gift
amount is a critical piece the administrators want to see.

Here is the code I have that works:

SELECT Gen_info.ID, Gen_info.FirstName, Gen_info.LastName, Max([Gift
Detail].Date) AS MaxOfDate
FROM Gen_info INNER JOIN [Gift Detail] ON Gen_info.ID = [Gift Detail].ID
GROUP BY Gen_info.ID, Gen_info.FirstName, Gen_info.LastName;

Here is the code that does not work when I add the [gift] field.

SELECT Gen_info.ID, Gen_info.FirstName, Gen_info.LastName, [Gift
Detail].Gift, Max([Gift Detail].Date) AS MaxOfDate
FROM Gen_info INNER JOIN [Gift Detail] ON Gen_info.ID = [Gift Detail].ID
GROUP BY Gen_info.ID, Gen_info.FirstName, Gen_info.LastName, [Gift
Detail].Gift;

Thanks for your help,

William
Nov 13 '05 #1
3 1740
Actually, the query is working properly. Since each gift amount is
different, it displays all gifts because it can't group differing
amounts. Try removing [Gift Detail].Gift from the group by clause and
put it in the select clause. Post-back if that doesn't work, and I'll
try it along with you in Access.

Nov 13 '05 #2
Thanks Johnny,

I tried your suggestion and got the following error message:

"You tried to execute a query that does not include the specified expression
'Gift' as part of an aggregate function."

This is the code I used which resulted in that error message:

SELECT Gen_info.ID, Gen_info.FirstName, Gen_info.LastName, [Gift
Detail].Gift, Max([Gift Detail].Date) AS MaxOfDate
FROM Gen_info INNER JOIN [Gift Detail] ON Gen_info.ID = [Gift Detail].ID
GROUP BY Gen_info.ID, Gen_info.FirstName, Gen_info.LastName;

William
"Johnny Meredith" <jm*******@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Actually, the query is working properly. Since each gift amount is
different, it displays all gifts because it can't group differing
amounts. Try removing [Gift Detail].Gift from the group by clause and
put it in the select clause. Post-back if that doesn't work, and I'll
try it along with you in Access.

Nov 13 '05 #3
Well, with help a Microsoft MVP, I was able to get the query right. I ended
up using a Subquery instead of a Totals query. Here's the code that works:

SELECT Gen_info.ID, [Gift Detail].[Gift ID], [Gift Detail].Gift,
Gen_info.LastName, Gen_info.FirstName, [Gift Detail].Date
FROM Gen_info INNER JOIN [Gift Detail] ON Gen_info.ID = [Gift Detail].ID
WHERE ((([Gift Detail].Date)=(SELECT Max([Date]) FROM [Gift Detail] WHERE ID
= [Gen_Info].ID)))
ORDER BY Gen_info.LastName, Gen_info.FirstName, Gen_info.FirstName;

Thanks,

William
"William Wisnieski" <wi***************@verizon.net> wrote in message
news:HbFle.1672$zb.57@trndny02...
Thanks Johnny,

I tried your suggestion and got the following error message:

"You tried to execute a query that does not include the specified expression 'Gift' as part of an aggregate function."

This is the code I used which resulted in that error message:

SELECT Gen_info.ID, Gen_info.FirstName, Gen_info.LastName, [Gift
Detail].Gift, Max([Gift Detail].Date) AS MaxOfDate
FROM Gen_info INNER JOIN [Gift Detail] ON Gen_info.ID = [Gift Detail].ID
GROUP BY Gen_info.ID, Gen_info.FirstName, Gen_info.LastName;

William
"Johnny Meredith" <jm*******@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Actually, the query is working properly. Since each gift amount is
different, it displays all gifts because it can't group differing
amounts. Try removing [Gift Detail].Gift from the group by clause and
put it in the select clause. Post-back if that doesn't work, and I'll
try it along with you in Access.


Nov 13 '05 #4

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

Similar topics

2
by: Shaiguy | last post by:
I have a table containing the following fields: ProjectUpdateID (PrimaryKey) ProjectID UpdateDate I would like to create a Query in Ms Access 2000 which will return me the most recent 2...
4
by: Mark Reed | last post by:
Hi all, I have a query (query1) which shows scan date, scan time & operator. One scan = 1 record. What I want to do is create a report based on query 2 from query1 which shows all the scans AND...
24
by: clare at snyder.on.ca | last post by:
I have a SQL query I need to design to select name and email addresses for policies that are due and not renewed in a given time period. The problem is, the database keeps the information for every...
8
by: Jason H | last post by:
Hi, I am sure I am just overlooking the obvious, but I am having a little trouble with this one... I am setting up an inventory database that tracks company tools and their location. This...
4
by: Sector 7G | last post by:
I'm working with a SQL query for a Human Resources database. Its intended purpose is to find all the paycheck records with a check date (prckhist.chkdate ) more recent than eleven days past the...
1
by: BurtonBach | last post by:
I have a query that selects any records in a table that have to do with units ordered. I would like to have a nested query that then selects the last three records from the above query. Here is...
7
by: jmstur2 | last post by:
I have a table with what I consider duplicate records. Data in all columns are duplicate except for the date column, meaning that duplicate data was entered on different dates and those dates were...
1
by: myemail.an | last post by:
Hi all, I have a table with this structure: Customer ID | Transaction date | Transaction type 1 | 1/2/2008 | F 1 | 1/4/2007 | M...
8
by: Dr Al | last post by:
I have a table with four date fields, some of which may not be filled in based on our data entry needs. I have a criteria set as <date()-180 which is supposed to pull dates older than 180 days ago....
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.