LIMIT 10..20 in SQL Server

后端 未结 15 2289
礼貌的吻别
礼貌的吻别 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:56

    The LIMIT clause is not part of standard SQL. It's supported as a vendor extension to SQL by MySQL, PostgreSQL, and SQLite.

    Other brands of database may have similar features (e.g. TOP in Microsoft SQL Server), but these don't always work identically.

    It's hard to use TOP in Microsoft SQL Server to mimic the LIMIT clause. There are cases where it just doesn't work.

    The solution you showed, using ROW_NUMBER() is available in Microsoft SQL Server 2005 and later. This is the best solution (for now) that works solely as part of the query.

    Another solution is to use TOP to fetch the first count + offset rows, and then use the API to seek past the first offset rows.

    See also:

    • "Emulate MySQL LIMIT clause in Microsoft SQL Server 2000"
    • "Paging of Large Resultsets in ASP.NET"

提交回复
热议问题