Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

Last n entries in a sqlserver table

Hi,
  How to show last 10 entries made in a sqlserver 2008 table?

Thanks a lot.
0
amitabh04
Asked:
amitabh04
1 Solution
 
WizillingCommented:
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
 
Gary DavisDir Internet SvcsCommented:
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
 
amitabh04Author Commented:
Hi,
  What be the query if there is no timestamp column or a sequential ID column?

Thanks.


0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
Anthony PerkinsCommented:
>> 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
 
Anthony PerkinsCommented:
>>What be the query if there is no timestamp column or a sequential ID column?<<
In other words, it cannot be done.
0
 
LowfatspreadCommented:
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now