dbTalk Databases Forums  

Query question - most recent historical record

comp.database.ms-access comp.database.ms-access


Discuss Query question - most recent historical record in the comp.database.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jording@pacbell.net
 
Posts: n/a

Default Query question - most recent historical record - 10-07-2003 , 05:28 PM






I have a database with payment details for members. Each member can
have multiiple payment records. What I would like to query for is the
most recent payment record for each member. Any help would be greatly
appreciated.

Using Access 2002

Reply With Quote
  #2  
Old   
bag
 
Posts: n/a

Default Re: Query question - most recent historical record - 10-08-2003 , 09:22 AM






jording (AT) pacbell (DOT) net (jording (AT) pacbell (DOT) net) wrote in message news:<a38ea64f.0310071428.74c6ca6 (AT) posting (DOT) google.com>...
Quote:
I have a database with payment details for members. Each member can
have multiiple payment records. What I would like to query for is the
most recent payment record for each member. Any help would be greatly
appreciated.

Using Access 2002
What fields are in this table?
Is there a unique identifier, a date/time field, etc?

If say you had an autonumber field as the unique identifier you could
simply do a SELECT Max(unique_identifier_field) FROM table WHERE
employee_id = XXX


Reply With Quote
  #3  
Old   
Philippa
 
Posts: n/a

Default Re: Query question - most recent historical record - 10-20-2003 , 08:38 AM



It would all depend on how you've structured you database, if you have
all the members in one table and the all their payments in another
with a member reference no., then you'd need to create to querys:

query one get all the membersIDs, and their last payment date.:

SELECT Max(paymentstable.PaymentDate) AS MaxPaymentDate,
paymentstable.MemberId
FROM paymentstable
GROUP BY paymentstable.MemberId;

query two, get the details of the Member and payments by joining the
Members, Payments tables together and query one to the payments table:

SELECT MembersTable.MemberName, PaymentsTable.PaymentDate,
PaymentsTable.PaymentAmount
FROM Query1 INNER JOIN (MembersTable INNER JOIN PaymentsTable ON
MembersTable.Id = PaymentsTable.MemberId) ON (Query1.MaxOfPaymentDate
= PaymentsTable.PaymentDate) AND (Query1.MemberId =
PaymentsTable.MemberId);

you should be able copy this above into the SQL view of a query then
change the field and table names to match yours.
I hope this helps....
Philippa ;o)

jording (AT) pacbell (DOT) net (jording (AT) pacbell (DOT) net) wrote in message news:<a38ea64f.0310071428.74c6ca6 (AT) posting (DOT) google.com>...
Quote:
I have a database with payment details for members. Each member can
have multiiple payment records. What I would like to query for is the
most recent payment record for each member. Any help would be greatly
appreciated.

Using Access 2002

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.