473,545 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.FirstN ame, Gen_info.LastNa me, 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.FirstN ame, Gen_info.LastNa me;

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

SELECT Gen_info.ID, Gen_info.FirstN ame, Gen_info.LastNa me, [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.FirstN ame, Gen_info.LastNa me, [Gift
Detail].Gift;

Thanks for your help,

William
Nov 13 '05 #1
3 1751
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.FirstN ame, Gen_info.LastNa me, [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.FirstN ame, Gen_info.LastNa me;

William
"Johnny Meredith" <jm*******@gmai l.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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.LastNa me, Gen_info.FirstN ame, [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.LastNa me, Gen_info.FirstN ame, Gen_info.FirstN ame;

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.FirstN ame, Gen_info.LastNa me, [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.FirstN ame, Gen_info.LastNa me;

William
"Johnny Meredith" <jm*******@gmai l.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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
3868
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 records (and also show the above 3 fields) So suppose the table looks like this:
4
4221
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 the difference between each scan. Something like below. I have spent days on this and can't figure it out. Date Time ...
24
19872
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 renewal in the history of the policyholder. The information is in 2 tables, policy and customer, which share the custid data. The polno changes...
8
14308
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 database has a table tblToolInfo and another table tblTransferHistory which are linked by a Tool ID field. As tools are checked out they are recorded in...
4
2739
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 employee's last raise (hrpersnl.p_paydate). It then totals the hours the employee worked from those records (prdehist.units), and if the total is within 40...
1
5676
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 the sql from my current query: SELECT .TransactionDate, .UnitsOrdered FROM WHERE (((.UnitsOrdered)>1)); And here is a sample of the data that...
7
3897
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 stored along with the data. I want to delete the records except for most recent one. I can select the client ID field and the max(date field) to...
1
1908
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 1 | 1/2/2008 | R 2 | 1//5/2007 | M 2 | 1/6/2007 | R
8
2769
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. The problem is that when I use that criteria for all four fields I am not getting the expected results. I am trying to find out from this query...
0
7401
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7807
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5971
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
703
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.