How to read the last row with SQL Server

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

    In order to retrieve the last row of a table for MS SQL database 2005, You can use the following query:

    select top 1 column_name from table_name order by column_name desc; 
    

    Note: To get the first row of the table for MS SQL database 2005, You can use the following query:

    select top 1 column_name from table_name; 
    

提交回复
热议问题