Select last 50 entries

ennrike

Registered User.
Local time
Yesterday, 18:50
Joined
Dec 3, 2010
Messages
25
Hi,

I would like to select last 50 entries for certain table, this table has a primary key a string and it has also the date for insertion of the entry.

What would be the SQL query to select the last 50 inserted rows of the table?
 
Try

SELECT TOP 50...
FROM...
ORDER BY...
 
ok, just one question:
TOP 50 would consider the date in that the row was inserted? I would have a column date named "InsertedId"

It is to say, the user would insert today a row, but the user would enter the inserting date by hand, in a field,

Would the "TOP" command take care of dates as well?
 
The key here is the Order By is the date of insertion Descending

Brian
 
The TOP predicate returns the number of records based on the ORDER BY clause. The data type is irrelevant. Sort the query in the desired manner and you'll get the last 50 entries.
 
Paul I'm puzzled by your post, I never mentioned the Data type, just the field Date of Insertion, and surely all I was doing was pointing out that the Order By had to be descending to get the last records by date.

Brian
 
I had not realized you jumped in Brian. I was responding to the OP's question of whether it would work for a date field.
 
No harm done, I get worried in my old age that I might be losing the plot. :D

Brian
 

Users who are viewing this thread

Back
Top Bottom