SQL Server SELECT LAST N Rows -


this known question best solution i've found like:

select top n * mytable order id desc 

i've table lots of rows. not posibility use query because takes lot of time. how can select last n rows without using order by?

edit

sorry duplicated question of this one

you can using row number partition feature also. great example can found here:

i using orders table of northwind database... let retrieve last 5 orders placed employee 5:

select orderid, customerid, orderdate (     select row_number() on (partition employeeid order orderdate desc) ordereddate,*     orders ) ordlist  ordlist.employeeid = 5 , ordlist.ordereddate <= 5 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -