Solved

Last n entries in a sqlserver table

Posted on 2011-09-26
6
172 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now