How to read the last row with SQL Server

后端 未结 17 828
别那么骄傲
别那么骄傲 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:13

    I think below query will work for SQL Server with maximum performance without any sortable column

    SELECT * FROM table 
    WHERE ID not in (SELECT TOP (SELECT COUNT(1)-1 
                                 FROM table) 
                            ID 
                     FROM table)
    

    Hope you have understood it... :)

提交回复
热议问题