Finally, Microsoft SQL Server 2012 was released, I really like its simplicity for a pagination, you don’t have to use complex queries like answered here.
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 useOFFSET ... FETCH
clause.OFFSET
clause is mandatory withFETCH
. You cannot useORDER BY ...
.
FETCHTOP
cannot be combined withOFFSET
andFETCH
in the same query
expression.