Retrieving the very last entry

merkava

Registered User.
Local time
Today, 15:12
Joined
Oct 16, 2006
Messages
25
Hello All,

Is there a way to retrieve the very last entry to a table (via a query) without passing a value to the query.

Lets say I have a table Pets

ID desc
==============
1 Dog
2 Cat
3 Lizard

For example lizard was added last, is there a way I could pull just this out using a query? (keep in mind that I don't know wahat the last entry is, so I cannot pass any kind of value to the query)

Cheers,
Aaron
 
assuming your id's are in sequence then

maxid = dmax("id","mytable")

then
lastpet=dlookup("desc","mytable","[id] = " & maxid)

will do it
 
Type/paste this in the SQL View of a new query and run the query.

SELECT TOP 1 [desc]
FROM [Pets]
ORDER BY [ID] DESC;

Note: The final DESC stands for Descending, not the field name [desc].

^
 
Last edited:

Users who are viewing this thread

Back
Top Bottom