How to select top N from a table

后端 未结 9 808
醉酒成梦
醉酒成梦 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:37
    SELECT ...
      LIMIT 25
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-11 21:43

    Select Top 25 [Column] From [Table] Order By [Column]

    If you have fewer than 25 records, this will just pull however many there are.

    0 讨论(0)
提交回复
热议问题