View Full Version : Filtering Multiple Records


Zed
07-17-2002, 07:29 AM
I have multiple records in a table with various timestamps. Is there a way to build a query that returns only the most recent record and not an aggregation of all the records with a maximum time?

Here is a sample of what my table is like:

Name Last Visit (date/time format) Widgets Purchased
Bill May 12, 1997 12:05:01 2
Bill Aug 11, 1999 10:05:00 1
Bob Dec 1, 2000 09:05:01 5
Bob Oct 10, 1999 05:20:10 6
Bob May 3, 2000 08:34:55 2
Mary Nov 1, 1999 10:02:00 4

And I'd like to pull the following results with my query

Name Last Visit Widgets Purchased
Bill Aug 11, 1999 10:05:00 1
Bob Dec 1, 2000 09:05:01 5
Mary Nov 1, 1999 10:02:00 4

Whenever I use the Max(Last Visit), I get a sum of widgets and not the number that they purchased at their last visit.

Thanks,
Zed

RichMorrison
07-17-2002, 07:51 AM
Make a "Totals" query where you Group By name. Then add Max([Last Visit]). Save as "qryOne" or something.

Make "qryTwo" where you join "qryOne" to your table based on Name and LastVisit. Select Name, LastVisit, Widgits.

RichM