-4

I want to select records after first 5 records in a table. The table is getting updated with new records. I have displayed 5 new records select top 5 * from table order by ID DESC.

Now I want to Display another 5 records somewhere else in the page, what will be the query for that?

Mansfield
  • 14,445
  • 18
  • 76
  • 112

2 Answers2

0
WITH tmp AS  
(SELECT ROW_NUMBER() OVER (ORDER BY a.id) AS 'rn', a.* FROM table a)
SELECT * FROM tmp WHERE rn BETWEEN 5 AND 10
Mansfield
  • 14,445
  • 18
  • 76
  • 112
  • @user2075460 Glad to hear it. You should mark it as the accepted answer then, by clicking the green check mark to the left of the answer. – Mansfield Oct 25 '13 at 13:35
0
SELECT  *
FROM  [dbo].[4]   
ORDER BY [id] ASC 
OFFSET  5 ROWS 
FETCH NEXT 10 ROWS ONLY
vhadalgi
  • 7,027
  • 6
  • 38
  • 67