How To retrive last 10 records from a table

Posted by Sudheep.grandhe under Sql Server on 6/7/2011 | Points: 10 | Views : 4786 | Status : [Member] | Replies : 6
Hello There,

Let us say I have table. I dont know how many records in that table. So, my intension is to retrive last 10 or 50 records from that table
Could any one pleae give this answer asap.

Best,
Sudheep.

Best,
Sudheep.



Responses

Posted by: Ratnesh2927 on: 6/7/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

I have solution in my mind. See if it works!!!

SELECT TOP 10 * FROM tbl_TableName ORDER BY id_field DESC


Thanks,

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 6/7/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi,

If in your table you have a key value then you can use it to do a descending and then get the top n values as per your requirement.

Thanks
Karthik
www.f5Debug.net

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gsolvers on: 6/7/2011 [Member] Starter | Points: 25

Up
0
Down
Yes the above will work if you have identity set. Let me know if you dont have that. There is alternate solution by moving all records to a temp table with identity set and executing the above query on the temporary table.

Best Regards,

VG
www.TeacherJi.com

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Siva.boggarapu on: 6/8/2011 [Member] Starter | Points: 25

Up
0
Down
Dear Sudheep,

SELECT TOP 10 * FROM tbl_TableName ORDER BY id_field DESC

I think it would be help for you.

Regards,
siva,
skyme:siva.boggarapu.ef

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakn2 on: 6/8/2011 [Member] Starter | Points: 25

Up
0
Down
try this

select * from (select top 10 * from emp1 order by empno desc) b order by empno

Thanks&Regards
LakshmiNarayana Nalluri.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Seenuvasan on: 6/13/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

if you have created_at date for each record..
you can sort that table based on created date in descending order . and get top 10 records.

Thanks,
Seen

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response