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 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.
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.
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.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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$) {
}
...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
| |