Function - Last Two Entry Dates

  • Thread starter Thread starter cru
  • Start date Start date
C

cru

Can I get your expert assistance on retrieving the last two most recent dates?

I have multiple records with time stamp in which I need to retrieve the last
two dates. I can do Min/Max to grab the first and last but not sure if there
is a simple function I can use.

Thanks for your help ahead of time.
 
Try this --
Substitute your table and field names.
SELECT [YourTable].*
FROM [YourTable]
WHERE [YourTable].[Entry Dates] = (SELECT TOP 2 [XX].[Entry Dates] FROM
[YourTable] AS [XX] ORDER BY [XX].[Entry Dates] DESC);
 
Try this --
Substitute your table and field names.
SELECT [YourTable].*
FROM [YourTable]
WHERE [YourTable].[Entry Dates] = (SELECT TOP 2 [XX].[Entry Dates] FROM
[YourTable] AS [XX] ORDER BY [XX].[Entry Dates] DESC);

minor correction: the = should be IN:

WHERE [YourTable].[Entry Dates] IN (SELECT TOP 2 [XX].[Entry Dates] FROM
 
Thank you so much to both of you both the reply. A really stupid questions,
what would the [XX] indicate?
 
cru said:
Thank you so much to both of you both the reply.
A really stupid questions, what would the [XX] indicate?

It is a synonym, shorthand, or alias for your table... set in the AS clause
of the SQL. As patched together from Karl and John, that would read:

SELECT [YourTable].* FROM [YourTable]
WHERE [YourTable].[Entry Dates] IN (SELECT TOP 2 [XX].[Entry Dates] FROM
[YourTable] AS [XX] ORDER BY [XX].[Entry Dates] DESC);

The only stupid questions are those we are too timid to ask.

Larry Linson
Microsoft Office Access MVP
 
Back
Top