select the TOP N rows from a table

后端 未结 5 1730
谎友^
谎友^ 2020-12-13 06:35

I am making some paging, and I need to make some query and get the result form defined slicing . for example: I need to get all \"top\" rows in range 20n < x < 40n et

5条回答
  •  青春惊慌失措
    2020-12-13 07:00

    From SQL Server 2012 you can use a native pagination in order to have semplicity and best performance:

    https://docs.microsoft.com/en-us/sql/t-sql/queries/select-order-by-clause-transact-sql?view=sql-server-ver15#using-offset-and-fetch-to-limit-the-rows-returned

    Your query become:

    SELECT * FROM Reflow  
    WHERE ReflowProcessID = somenumber
    ORDER BY ID DESC;
    OFFSET 20 ROWS  
    FETCH NEXT 20 ROWS ONLY;  
    

提交回复
热议问题