Solved Show Last Record in Query by Date (1 Viewer)

theinviter

Registered User.
Local time
Yesterday, 17:13
Joined
Aug 14, 2014
Messages
244
Dears;
Need help,
How to filter the query to show only last record by date, as the filed name DATE_.

thanks
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:13
Joined
May 7, 2009
Messages
19,249
you create another query (qry1) that will retrieve PK number and the Max of date:

select [PK field], Max([yourDateField]) As MaxOfDate from yourTable;

now join this qry to your Original query and join them on the two fields.
 

XPS35

Active member
Local time
Today, 02:13
Joined
Jul 19, 2022
Messages
163
Can be done 1 query.
Code:
SELECT TOP 1 * FROM YourTable ORDER BY DATE_ DESC

Even arnelgp's solution can be done In one query using a sub-query.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:13
Joined
May 7, 2009
Messages
19,249
Even arnelgp's solution can be done In one query using a sub-query
your query will return only 1 record?
what if there are many PKs/Date on the table?
 

XPS35

Active member
Local time
Today, 02:13
Joined
Jul 19, 2022
Messages
163
your query will return only 1 record?
what if there are many PKs/Date on the table?
Then only one record will be shown.
The wish was "only last record by date". So 1 record.

Edit: If the time parts of a same date differ, your query will also select 1 record.
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:13
Joined
Feb 19, 2002
Messages
43,631
Sorry, but why would you ever name a field "DATE_"? You were right to not use Date because Date is the name of a function and as you probably discovered, you had trouble with a field named Date in VBA. But maybe you could use SaleDate or something more descriptive than a trailing underscore.

Simple is better. Use the Top 1 query.
 

Users who are viewing this thread

Top Bottom