How to query for latest record by date & time?

H

hkgary33

Dear all,
I've built a table with three fields: NAME;DATE;TIME
this table will be automatically append a new record with current date and
time in the DATE & TIME field when the user input their name in the NAME
field. So, if a user input his own name in two different time period, two new
records will be appended,and the table will like:
NAME DATE TIME
Gary 2006-07-10 16:30:00
Gary 2006-07-10 17:10:00


The problem is that I want to perform a QUERY so that when the user input the
NAME field, I can search out and display the latest date and time of that
particular user....but I don't know how to use SQL statement to find out the
latest date and time fields.....can you all help me for writing such a
statement?
THANKS A LOT!!!!
 
A

Allen Browne

1. For starters, Name, Date, and Time are all reserved words in JET SQL.
Rename the fields to something else so they are not ambiguous.

2. Consider combining the date and time into one field.
That will make it easier to query.

3. Having done that, create a query using this table.
3.1 In query design view, depress the Total button on the toolbar.
Access adds a Total row to the grid.
3.2 Drag your name field into the grid.
Accept Group By under this field.
3.3 Drag the date/time field into the grid.
Choose Max in the Total row under this field.

The query now shows the most recent date/time value for each name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top