How to select the nth row in a SQL database table?

后端 未结 30 2887
执笔经年
执笔经年 2020-11-22 06:06

I\'m interested in learning some (ideally) database agnostic ways of selecting the nth row from a database table. It would also be interesting to see how this can b

30条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 06:41

    T-SQL - Selecting N'th RecordNumber from a Table

    select * from
     (select row_number() over (order by Rand() desc) as Rno,* from TableName) T where T.Rno = RecordNumber
    
    Where  RecordNumber --> Record Number to Select
           TableName --> To be Replaced with your Table Name
    

    For e.g. to select 5 th record from a table Employee, your query should be

    select * from
     (select row_number() over (order by Rand() desc) as Rno,* from Employee) T where T.Rno = 5
    

提交回复
热议问题