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
.
For SQL Server:
select top 25 * from table order by Num asc
For mySQL:
select * from table order by Num asc limit 25
In Firebird,
select first 25
from your_table
order by whatever
select top 25 *
from your_table
order by Num asc
On SQL Server that would select the 25 first records starting from the lowest value of Num. If you need the highest, use "desc" instead of "asc".
Not sure I understand the requirement, but you can do:
SELECT TOP 25 Num FROM Blah WHERE Num = 'MyCondition'
If there aren't 25 records, you won't get 25. You can perform an ORDER BY
and the TOP
will listen to that.
Oracle:
Select *
FROM Table
WHERE rownum <= 25
MSSQL:
SELECT TOP 25 *
from Table
Mysql:
SELECT * FROM table
LIMIT 25
Depending on the database implementation you're using, it could be using the limit statement (as one other answer suggests) or it could be like this:
SELECT TOP 25 Num, blah, blah ...