Solved

Last n entries in a sqlserver table

Posted on 2011-09-26
6
173 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

762 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