Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Am new to SQL SERVER 2008

How can i get the last 30 entered record on a database using Sql commands/statements

Thanks in Advance
Posted

1 solution

The only way to guarantee getting the last entered is to timestamp the records when you create them, but including a datetime column in the table. This allows you to use the ORDER BY clause in your select query, and then return the top 30 results:
SQL
SELECT TOP 30 * FROM MyTable ORDER BY EnteredAt DESC
If you don't supply ORDER BY, the SQL is at liberty to return records in any order if finds convenient (normally, it's in modification order, but it's not guaranteed, particularly if records are deleted and the space is reused later)
 
Share this answer
 
Comments
Puseletso Michelle 26-Apr-13 5:58am    
Thanks :-)
OriginalGriff 26-Apr-13 6:07am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900