Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a table named "Details" with column "Name". This column contains lots of values which are already been entered in the table. Currently I have entered some values to the column "Name". I need to show last entered 10 values. We have a query in sql to show first values top(10) values. Like to that I need bottom values(last entered values).
Posted
Comments
[no name] 25-Mar-14 7:50am    
Get your data, sort it last first then take the top 10.

you can do something like this using order by clause:-

select top 10 * from Tbl_Name order by Name desc
 
Share this answer
 
In order to show the "top n" values (or the "bottom n" values for that matter) you have to specifically apply an order to the rows, becuase otherwise SQL is at liberty to return rows an any order which suits it - which may be "last entered order" but does not have to be - nor does it have to be the same order twice in a row.

So, the best way to do this is to add a "timestamp" field to your database, so that you put the date and time you entered them into the row.
then it's simple:
SQL
SELECT TOP 10 * FROM MyTable ORDER BY EnterDate DESC
 
Share this answer
 
try this.. :)


SQL
select top 10 * from TableName order by id desc
 
Share this answer
 
Order your records in creating time descending and get the top 10.

If you don't have creation time column, you can do that easily, just make a new column type datetime and make GETDATE() to default value to it. After you can make a descending order by that.
 
Share this answer
 
v3

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