selecting the top 1 record

DanielR

Registered User.
Local time
Today, 03:26
Joined
Mar 16, 2018
Messages
72
in sql you can do a select with top(1) parameter.
How do you implement this in Access?
 
I believe I figured it out...using Last()
 
No you didn't - if you want Top, use Top.
If you go to the link I posted, you will see the definition, syntax and an example you can "experiment with".

Try the sample.

SELECT top 1 postalcode
FROM Customers
WHERE Country='Germany'
order by postalcode desc;
 
Thank you jdraw...that link is very helpful
 
DanielR - be VERY careful when using First or Last for anything to do with a table.

Remember that unless you are opening a query-based recordset, you get whatever order the table is in, not sorted at all, and with no guarantee of any particular order. Tables have NO inherent order of record presentation.

That is because of the way Access does some of its updates. It doesn't update the original record. It updates a new COPY of the record, then deletes the original and threads the new record into the table, but not necessarily at the same position.
 
Here is my issue:

I have a table with the following fields:
Project ID
Comment
User Name
Date

For each Project ID I would like to get the LAST Comment, User Name and Date.
The LAST meaning the newest comment entered.
Hope this makes sense.
I am having a hard time formulating the SQL statement.
 
@DanielR,
In addition to the info received, as Pat said you should be aware that Date is a reserved word in Access. Here is a list of other reserved words.
Also, having names with embedded spaces often leads to syntax errors. Many will suggest that you use names without embedded spaces and without "special characters"(!@#$%^&* etc). Best to use alphanumerics and "_" underscore only.
 
Thank you...appreciate everyone's input especially Pat and Jdrew.
 

Users who are viewing this thread

Back
Top Bottom