Microsoft SQL Server Pagination SQL Server 2012/2014 using ORDER BY OFFSET and FETCH NEXT

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

For getting the next 10 rows just run this query:

SELECT * FROM TableName ORDER BY id OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY;

Key points to consider when using it:

  • ORDER BY is mandatory to use OFFSET and FETCH clause.
  • OFFSET clause is mandatory with FETCH. You can never use, ORDER BYFETCH.
  • TOP cannot be combined with OFFSET and FETCH in the same query expression.


Got any Microsoft SQL Server Question?