LIMIT 10..20 in SQL Server

后端 未结 15 2619
礼貌的吻别
礼貌的吻别 2020-11-22 11:21

I\'m trying to do something like :

SELECT * FROM table LIMIT 10,20

or

SELECT * FROM table LIMIT 10 OFFSET 10
15条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 11:40

    So far this format is what is working for me (not the best performance though):

    SELECT TOP {desired amount of rows} * 
    FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY {order columns} asc)__row__ FROM {table})tmp
    WHERE __row__ > {offset row count}
    

    A note on the side, paginating over dynamic data can lead to strange/unexpected results.

提交回复
热议问题