How to select top N from a table

后端 未结 9 829
醉酒成梦
醉酒成梦 2020-12-11 21:18

I have to select the top 25 records from a table according to the column Num.

There are two issues. First, the table is not sorted by Num.

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-11 21:40

    It depends heavily on your database, as there is no standard way to do this.

    In SQL Server, for example, I have used Row_Number (http://msdn.microsoft.com/en-us/library/ms186734.aspx) to do this, so I can select which group I was interested in (for paging, for example), but Top also works.

    For Oracle you can look at rownum (http://www.adp-gmbh.ch/ora/sql/examples/first_rows.html).

    And MySQL has been mentioned already.

提交回复
热议问题