First and last function query filtering issues (1 Viewer)

pravistar

New member
Local time
Today, 20:51
Joined
Jun 12, 2020
Messages
2
Hi,

I am facing issues filtering data with data from a table. My table details are as below


ClaimNumber: Short text
ClaimDate : Date
PaymentDate : Date/time
Part : $ Currency
Labor: $ Currency
Misc : $ Currency
Total : $ Currency.

ClaimType : Short Text

As Claim payments normally coming as installments, the claim number keeps repeating in the table. 1st payment came on 01.06.2020 and then the second payment on 08.06.2020 like that.
I want to make a query that can retrieve the data with respect to the last payment date against each claim. I have used Last and max functions. For some records output for the query is correct but for some not. Awaiting your feedback.

Thanks
Praveen
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:51
Joined
May 7, 2009
Messages
19,231
use the Max() function in your query:

select ClaimNumber, Max(ClaimDate) As MaxOfClaimDate From yourTable Group By ClaimNumber;
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:51
Joined
Feb 19, 2002
Messages
43,213
First and Last are 100% dependent on the order of a recordset and if you haven't sorted the recordset using a query, you cannot ever rely on consistency. arne's suggestion of finding the Max() date for a claim will find the "last" payment" and using Min() for the date will find the "first" payment.

Always use Min/Max rather than First/Last when that is what you actually want.

In a relational database (not just Access), tables and queries are unordered sets so First and Last have no meaning.
 

Users who are viewing this thread

Top Bottom