SQL Snippets


Paging

Paging bei großen Abfragen

MSSQL Server < 2012:
;with PagingTable as (
select *, row_number() over (order by OrderColumnName) as RowNumber
from TableName
)
select *
from PagingTable
where RowNumber between 10 and 20;
MSSQL Server >= 2012:
select *
from TableName
offset 10
fetch next 10 rows only;
MySQL, PostgreSQL:
select *
from TableName
limit 10
offset 10;