T-SQL How to select only Second row from a table?

前端 未结 15 1356
攒了一身酷
攒了一身酷 2020-12-28 12:31

I have a table and I need to retrieve the ID of the Second row. How to achieve that ?

By Top 2 I select the two first rows, but I need only

15条回答
  •  星月不相逢
    2020-12-28 12:58

    In SQL Server 2012+, you can use OFFSET...FETCH:

    SELECT
       
    FROM
       
    ORDER BY
       
    OFFSET 1 ROWS   -- Skip this number of rows
    FETCH NEXT 1 ROWS ONLY;  -- Return this number of rows
    

提交回复
热议问题