Solved

Last n entries in a sqlserver table

Posted on 2011-09-26
6
175 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
Veeam gives away 10 full conference passes

Veeam is a VMworld 2017 US & Europe Platinum Sponsor. Enter the raffle to get the full conference pass. Pass includes the admission to all general and breakout sessions, VMware Hands-On Labs, Solutions Exchange, exclusive giveaways and the great VMworld Customer Appreciation Part

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

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…
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

632 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