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

Problems Querying Last Donation in Donation Table

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
3 2003
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Marc Pelletier | last post by:
Hello, I have a table with a Day field, defined as smalldatetime. I am filling it from a CSharp application with the following code: DataRow r = dtStaDays.NewRow(); r= station_ID; r =...
3
by: daveland | last post by:
I am working on some JavaScript that dynamically adds rows to a table in response to a button click. A new row does appear on the screen when the button is clicked. However, that table to which a...
5
by: Shane | last post by:
I wonder if someone has any ideas about the following. I am currently producing some reports for a manufacturing company who work with metal. A finished part can contain multiple sub-parts to...
8
by: Jean | last post by:
Hello all, I have the following data, that was queried and sorted to columns PROBLEM_ID and then by STATUSDATE (ascending): STATUS_ID STATUSDATE PROBLEM_ID --------- ---------- ...
4
by: pietlinden | last post by:
Hi, I have the sort of standard Donors/Donations DB. The twist I have is that donations can be time, money (which are easy, because they're additive), but then a donor can make an in-kind pledge,...
3
by: MDB | last post by:
I'd normally Google for a question like this, and hope to snag a few examples along with the answer, but this time I can't see to get the keywords specific enough. Or I'd ask coworkers, but...
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
2
by: bwana.mpoa | last post by:
Hi, We're using a mySQL database as a replica of another (Sybase) DB for reporting purposes. The Sybase is part of a real-time mission critical system - hence the separate database where people...
2
by: RajSharma | last post by:
Hi, I am facing a problem regarding querying thru a large table having millions of rows....... Its hanging in between while querying for all those rows Can anybody suggest me a query regarding :...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.