0

I want to create paging using T-SQL. How can I select 10 rows from 11th row to 20th row?

I know I can do this with C# etc. But my question is about SQL Server.

Here is the table:

CREATE TABLE EarlyAccess(
    [EarlyAccessUserId] [int] IDENTITY(1,1) NOT NULL,
    [FirstName] [nvarchar](50) NOT NULL,
    [Lastname] [nvarchar](50) NOT NULL
)
4

1 に答える 1

4
SELECT  *
FROM    (
        SELECT  *, ROW_NUMBER() OVER (ORDER BY earlyAccessUserId) rn
        FROM    earlyAccess
        ) q
WHERE   rn BETWEEN 11 AND 20
ORDER BY
        earlyAccessUserId

There is not such thing as n'th record in SQL unless you explicitly specify ordering.

于 2012-06-04T11:00:36.527 に答える