By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,519 Members | 2,416 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,519 IT Pros & Developers. It's quick & easy.

Problems Querying Last Donation in Donation Table

P: n/a
Hi all!

I have an Access 2000 database for the Habiat for Humanity where I work.
This is the second database I have written and it gets a bit more complex
each time... I have learned much and read much over the last few months and
have found leads to the answers to several other problems I have encountered
with a Google search of past posts/threads.
SO thank you for the help already rendered even though you didn't know!!

My problem is this I want to pull a query with just the LAST donation from
all donors (as opposed to just the "last donation")
The data is stored in two tables tblCntc and tblDonations
I can pull everything together with query called QryCntcDonationsLast and
set the "total" to Last and get ALMOST what I need.
SQL reads:
SELECT tblCntc.CntcID, tblCntc.Cntc1FirstName, tblCntc.Cntc1LastName,
tblCntc.CntcOrganization, Last(tblDNDonations.DNDate) AS LastOfDNDate
FROM tblDNDonations INNER JOIN tblCntc ON tblDNDonations.DNID =
tblCntc.CntcID
GROUP BY tblCntc.CntcID, tblCntc.Cntc1FirstName, tblCntc.Cntc1LastName,
tblCntc.CntcOrganization;

As it is written this works fine - but what I NEED are additional fields
from the tblDonations like amount, purpose, etc. WHEN I add ANYoff these
the LAST element appears to not work and the query begins to return more
than just the LAST donation from donors.

I have read several posts about the dmax or max and have tried several of
the suggestions but they don't seem to work and return either all the
donations or don't work.

ANY help will be appreciated. I have spent several hours over the last few
evenings and have not had any sucess.

Thanks

Andy

FYI: My next step is to add a volunteer scheduling component and will need a
similar query for when volunteers were last scheduled.
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I think if you have 1 query (Query1) just returning the CntcID and the
LastOfDNDate, and then create a second query with whatever information you
want. That would consist of your 2 table + Query 1 but join the 2 CntcIDs
and the LastOfDNDate to the DNDate. That should only pull information
applicable to the last donation date
HTH

Phil
"AndyBell" <jb***@NOSPAMleecountyhabitat.org> wrote in message
news:vv************@corp.supernews.com...
Hi all!

I have an Access 2000 database for the Habiat for Humanity where I work.
This is the second database I have written and it gets a bit more complex
each time... I have learned much and read much over the last few months and have found leads to the answers to several other problems I have encountered with a Google search of past posts/threads.
SO thank you for the help already rendered even though you didn't know!!

My problem is this I want to pull a query with just the LAST donation from
all donors (as opposed to just the "last donation")
The data is stored in two tables tblCntc and tblDonations
I can pull everything together with query called QryCntcDonationsLast and
set the "total" to Last and get ALMOST what I need.
SQL reads:
SELECT tblCntc.CntcID, tblCntc.Cntc1FirstName, tblCntc.Cntc1LastName,
tblCntc.CntcOrganization, Last(tblDNDonations.DNDate) AS LastOfDNDate
FROM tblDNDonations INNER JOIN tblCntc ON tblDNDonations.DNID =
tblCntc.CntcID
GROUP BY tblCntc.CntcID, tblCntc.Cntc1FirstName, tblCntc.Cntc1LastName,
tblCntc.CntcOrganization;

As it is written this works fine - but what I NEED are additional fields
from the tblDonations like amount, purpose, etc. WHEN I add ANYoff these
the LAST element appears to not work and the query begins to return more
than just the LAST donation from donors.

I have read several posts about the dmax or max and have tried several of
the suggestions but they don't seem to work and return either all the
donations or don't work.

ANY help will be appreciated. I have spent several hours over the last few evenings and have not had any sucess.

Thanks

Andy

FYI: My next step is to add a volunteer scheduling component and will need a similar query for when volunteers were last scheduled.

Nov 12 '05 #2

P: n/a
as a quick test, I created tblOne
id (pk)
lastName

id lastname
1 cane
2 able

and tblTwo
id (pk) (uk)
seq (pk)
date (uk)
donation

id seq date donation
1 1 1/3/2004 8
1 2 1/4/2004 9
2 1 1/5/2004 10
2 2 1/6/2004 11

since you want the donation for the last date, I assume that every
date in tblTwo is unique ?

then I created qry2
SELECT tblTwo.id, Last(tblTwo.date) AS LastOfdate
FROM tblTwo
GROUP BY tblTwo.id;

id lastDate
1 1/4/2004
2 1/6/2004
then I created qry1
SELECT tblOne.lastName, qry2.LastOfdate, tblTwo.donation
FROM (tblOne INNER JOIN qry2 ON tblOne.id = qry2.id) INNER JOIN
tblTwo ON
(qry2.LastOfdate = tblTwo.date) AND (qry2.id = tblTwo.id);
^^^^ - this is based on my assumption above

lastName lastDate donation
cane 1/4/2004 9
able 1/6/2004 11

is this what you need ?
if my assumption is incorrect, which donation amount would you want
for id 2 ?
id seq date donation
1 1 1/3/2004 8
1 2 1/4/2004 9
2 1 1/5/2004 10
2 2 1/5/2004 11

"AndyBell" <jb***@NOSPAMleecountyhabitat.org> wrote in message news:<vv************@corp.supernews.com>...
Hi all!

I have an Access 2000 database for the Habiat for Humanity where I work.
This is the second database I have written and it gets a bit more complex
each time... I have learned much and read much over the last few months and
have found leads to the answers to several other problems I have encountered
with a Google search of past posts/threads.
SO thank you for the help already rendered even though you didn't know!!

My problem is this I want to pull a query with just the LAST donation from
all donors (as opposed to just the "last donation")
The data is stored in two tables tblCntc and tblDonations
I can pull everything together with query called QryCntcDonationsLast and
set the "total" to Last and get ALMOST what I need.
SQL reads:
SELECT tblCntc.CntcID, tblCntc.Cntc1FirstName, tblCntc.Cntc1LastName,
tblCntc.CntcOrganization, Last(tblDNDonations.DNDate) AS LastOfDNDate
FROM tblDNDonations INNER JOIN tblCntc ON tblDNDonations.DNID =
tblCntc.CntcID
GROUP BY tblCntc.CntcID, tblCntc.Cntc1FirstName, tblCntc.Cntc1LastName,
tblCntc.CntcOrganization;

As it is written this works fine - but what I NEED are additional fields
from the tblDonations like amount, purpose, etc. WHEN I add ANYoff these
the LAST element appears to not work and the query begins to return more
than just the LAST donation from donors.

I have read several posts about the dmax or max and have tried several of
the suggestions but they don't seem to work and return either all the
donations or don't work.

ANY help will be appreciated. I have spent several hours over the last few
evenings and have not had any sucess.

Thanks

Andy

FYI: My next step is to add a volunteer scheduling component and will need a
similar query for when volunteers were last scheduled.

Nov 12 '05 #3

P: n/a
Phil & Roger,
Thanks for your help.
Phil had the right answer,[twin/dbl join] but something Roger said tipped me
off to my mistake. "I assume that every date in tblTwo is unique"

The donations table has about 900 records. When drilled down with the Last
query it returns about 350 records - one date for each donor -however what
was throwing me off was that many donors have multiple donations on the SAME
day....

Had I realized this 18 months ago I would have created a "donation date"
table with related "donated items" table... [so now I have to wrestle with
changing that data "for the long term good" or "its not that important"]

Thanks again!
Andy

"Roger" <le*********@natpro.com> wrote in message
news:8c**************************@posting.google.c om...
as a quick test, I created tblOne
id (pk)
lastName

id lastname
1 cane
2 able

and tblTwo
id (pk) (uk)
seq (pk)
date (uk)
donation

id seq date donation
1 1 1/3/2004 8
1 2 1/4/2004 9
2 1 1/5/2004 10
2 2 1/6/2004 11

since you want the donation for the last date, I assume that every
date in tblTwo is unique ?

then I created qry2
SELECT tblTwo.id, Last(tblTwo.date) AS LastOfdate
FROM tblTwo
GROUP BY tblTwo.id;

id lastDate
1 1/4/2004
2 1/6/2004
then I created qry1
SELECT tblOne.lastName, qry2.LastOfdate, tblTwo.donation
FROM (tblOne INNER JOIN qry2 ON tblOne.id = qry2.id) INNER JOIN
tblTwo ON
(qry2.LastOfdate = tblTwo.date) AND (qry2.id = tblTwo.id);
^^^^ - this is based on my assumption above

lastName lastDate donation
cane 1/4/2004 9
able 1/6/2004 11

is this what you need ?
if my assumption is incorrect, which donation amount would you want
for id 2 ?
id seq date donation
1 1 1/3/2004 8
1 2 1/4/2004 9
2 1 1/5/2004 10
2 2 1/5/2004 11

"AndyBell" <jb***@NOSPAMleecountyhabitat.org> wrote in message

news:<vv************@corp.supernews.com>...
Hi all!

I have an Access 2000 database for the Habiat for Humanity where I work.
This is the second database I have written and it gets a bit more complex each time... I have learned much and read much over the last few months and have found leads to the answers to several other problems I have encountered with a Google search of past posts/threads.
SO thank you for the help already rendered even though you didn't know!!

My problem is this I want to pull a query with just the LAST donation from all donors (as opposed to just the "last donation")
The data is stored in two tables tblCntc and tblDonations
I can pull everything together with query called QryCntcDonationsLast and set the "total" to Last and get ALMOST what I need.
SQL reads:
SELECT tblCntc.CntcID, tblCntc.Cntc1FirstName, tblCntc.Cntc1LastName,
tblCntc.CntcOrganization, Last(tblDNDonations.DNDate) AS LastOfDNDate
FROM tblDNDonations INNER JOIN tblCntc ON tblDNDonations.DNID =
tblCntc.CntcID
GROUP BY tblCntc.CntcID, tblCntc.Cntc1FirstName, tblCntc.Cntc1LastName,
tblCntc.CntcOrganization;

As it is written this works fine - but what I NEED are additional fields
from the tblDonations like amount, purpose, etc. WHEN I add ANYoff these the LAST element appears to not work and the query begins to return more
than just the LAST donation from donors.

I have read several posts about the dmax or max and have tried several of the suggestions but they don't seem to work and return either all the
donations or don't work.

ANY help will be appreciated. I have spent several hours over the last few evenings and have not had any sucess.

Thanks

Andy

FYI: My next step is to add a volunteer scheduling component and will need a similar query for when volunteers were last scheduled.

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.