How to read the last row with SQL Server

后端 未结 17 841
别那么骄傲
别那么骄傲 2020-11-29 03:40

What is the most efficient way to read the last row with SQL Server?

The table is indexed on a unique key -- the \"bottom\" key values represent the last row.

17条回答
  •  悲哀的现实
    2020-11-29 04:08

    OFFSET and FETCH NEXT are a feature of SQL Server 2012 to achieve SQL paging while displaying results.

    The OFFSET argument is used to decide the starting row to return rows from a result and FETCH argument is used to return a set of number of rows.

    SELECT *
    FROM table_name
    ORDER BY unique_column desc
    OFFSET 0 Row
    FETCH NEXT 1 ROW ONLY
    

提交回复
热议问题