Subquery instead of DMax

I have two tables inside an Access Database
1) Donators
 ID_Donator
First Name
Last Name, etc

2) Donations
ID_Donator
Date_Donation
Amount

I want to create a query (WITHOUT WORKING WITH DMAX)  that allows me to obtain
these data :
ID_DONATOR,First Name, LastName, Date of his last donation, Amount of his last donation.

I've tried with subqueries but I dont obtain what I want.

I know tat this is quite easy with DMAX function but I want to explore an alternative solution with subqueries.

Thank you for your help
Carlos_MEJIAAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GRayLCommented:
You don't need a sub-query:

SELECT a.ID_Donator, a.[First Name], a.[Last Name], Max(b.Date_Donation], b.Amount
FROM Donators a INNER JOIN Donations b ON a.ID_Donator = b.ID_Donator
GROUP BY .ID_Donator, a.[First Name], a.[Last Name], b.Amount
Bruce SmithSoftware Engineer IICommented:
I don't think you need a subquery. Try this as it should return the amount of the last donation from a donor:
 
SELECT ID_Donator, First Name, Last Name, Date_Donation, Amount FROM Donators, Donations WHERE Donators.ID_Donator = Donations.ID_Donator GROUP BY ID_Donator;

Open in new window

Dale FyeOwner, Dev-Soln LLCCommented:
GrayL,

I don't think that is going to do it.  How is that going to provide both the date and amount of the last donation? With b.Amount in the GROUP BY clause, it is going to give you multiple records (one for each donation amount) for each donor (but all listing the Max of the Date_Donation field).

How about:

SELECT a.ID_Donator, a.[First Name], a.[Last Name], b.[Date_Donation], b.[Amount]
FROM Donators as a
INNER JOIN Donations as b
WHERE B.[Date_Donation] = (SELECT MAX([Date_Donation]) FROM Donations WHERE [ID_Donator] = a.ID_Donator)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

GRayLCommented:
Dale:  Right you are.  Take it away.
Carlos_MEJIAAuthor Commented:
Thank you some much to all and particularly to fyed that found the right way !!!

Carlos
Dale FyeOwner, Dev-Soln LLCCommented:
Glad to help.  

There are issues with subqueries, one of which is the updateability (or rather lack thereof) of the resulting recordset.  Using DMAX will generally provide an updateable recordset, so there may be advantages to using that method.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.