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
.
SELECT ...
LIMIT 25
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.
Select Top 25 [Column] From [Table] Order By [Column]
If you have fewer than 25 records, this will just pull however many there are.