On Tue, 19 Jun 2007 17:45:20 -0700, (e-mail address removed) wrote:
I have a table with 5 fields
ID PersonID Date Amount and Type
I want a query with the last record of each person based on date and I
want the results like this
PersonID LastOfDate Amount Type
How can i do that
thanks
A Subquery will do this:
SELECT PersonID, [Date], Amount, Type
FROM tablename
WHERE [Date] =
(SELECT Max([Date]) FROM tablename AS X
WHERE X.PersonID = tablename.PersonID);
John W. Vinson [MVP]
thanks
your sql works faster then dmax but if a person hes tow trans in a
same date I get tow records for this person
The same would be true of DMax, and the same is true logically. If you had the
transactions on stacks of paper, and you wanted the most recent transaction,
and you found two sheets of paper saying June 18 - which of those two is "the
most recent"? If there are two records, with different amounts and different
types, both on the same day, which one do you want to see?
You can, if you wish, store the date AND TIME of the transaction by setting it
to Now() rather than to Date(); unless there are two transactions the same
microsecond you'll only get one.
John W. Vinson [MVP]- Hide quoted text -
- Show quoted text -