Query - returning latest date/time from multiple records

I

IanB

I have a mental block!

I have a table with 2 fields.
A location field (text 4)
A date/time stamp field (Date/Time)
I can have multiple records for the same location.
I need to extract from all the location fields, only 1 record per location,
that being the newest date/time.

I can do this in code but there must be an SQL selection that will produce
the same result!
Any help apreciated

TIA

Ian B
 
K

Ken Snell [MVP]

SELECT * FROM Tablename
WHERE Tablename.DateTimeField =
(SELECT Max(T.DateTimeField)
FROM Tablename AS T
WHERE T.LocationField = Tablename.LocationField);
 
I

IanB

Ken

Thats great - thanks for your help

Ian B

Ken Snell said:
SELECT * FROM Tablename
WHERE Tablename.DateTimeField =
(SELECT Max(T.DateTimeField)
FROM Tablename AS T
WHERE T.LocationField = Tablename.LocationField);
 

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