Search code examples
sqlsql-serverrecords

Select records after 5 records in a table


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?


Solution

  • 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