Solved

Last n entries in a sqlserver table

Posted on 2011-09-26
6
174 Views
Last Modified: 2012-05-12
Hi,
  How to show last 10 entries made in a sqlserver 2008 table?

Thanks a lot.
0
Comment
Question by:amitabh04
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 13

Expert Comment

by:Wizilling
ID: 36614588
select top 10 * from your table
order by ColumnA desc

assuming ColumnA is a incrementing column value. eg Date time field.. or a identity field...
0
 
LVL 18

Expert Comment

by:Gary Davis
ID: 36615275
If there is a timestamp column or a sequential ID column

   SELECT TOP 10 * FROM table ORDER BY idcolumn DESC

Will display the last 10 rows (reverse sorted, of course).

Gary Davis
0
 

Author Comment

by:amitabh04
ID: 36644823
Hi,
  What be the query if there is no timestamp column or a sequential ID column?

Thanks.


0
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 36665345
>> What be the query if there is no timestamp column or a sequential ID column?<<
That would be:
SELECT TOP 10 *
FROM YourTable
ORDER BY YouAreSimplyOutOfLuck Desc
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 36665638
>>What be the query if there is no timestamp column or a sequential ID column?<<
In other words, it cannot be done.
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 36711008
define what you mean by last
show us the definition of the table
why/when do you want to do this
what logging method is the database using?
do you have any log reader software (eg redgate)

but you could be out of luck if your business rules/requirements have not determined and addressed this requirement
in the set up of your system...
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question