Selecting Nth Record in an SQL Query

后端 未结 12 752
悲&欢浪女
悲&欢浪女 2020-12-28 23:33

I have an SQL Query that i\'m running but I only want to select a specific row. For example lets say my query was:

Select * from Comments

L

12条回答
  •  被撕碎了的回忆
    2020-12-28 23:55

    Well, in T-SQL (the dialect for SQL Server) you can do the following:

    SELECT TOP 1 *
      FROM (SELECT TOP 8 *
              FROM Table
             ORDER
                BY SortField)
     ORDER
        BY SortField DESC
    

    This way you get the 8th record.

提交回复
热议问题