How to select top N from table

I need to select the 25 best entries from the table according to the column Num.

There are two questions. Firstly, the table is not sorted Num. I know that this can be solved using GROUP ORDER BY. Secondly, the number of entries in the table may be less than 25.

Is there a way to make this selection in only one SQL statement?

+3
source share
9 answers

For SQL Server:

select top 25 * from table order by Num asc

For mySQL:

select * from table order by Num asc limit 25
+9
source

Oracle:

Select *
FROM Table
WHERE rownum <= 25

MSSQL:

SELECT TOP 25 * 
from Table

Mysql:

SELECT * FROM table
LIMIT 25
+3
source
select top 25 *
from your_table
order by Num asc

SQL Server, 25 , Num. , "desc" "asc".

+1

( ), :

SELECT TOP 25 Num, blah, blah ...
+1
+1
SELECT ...
  LIMIT 25
0

Not sure I understand this requirement, but you can do:

SELECT TOP 25 Num FROM Blah WHERE Num = 'MyCondition'

If there are no 25 records, you will not receive 25. You can perform ORDER BYand TOPwill listen to it.

0
source

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

If you have less than 25 entries, it just pulls as much as you like.

0
source

In firebird

select first 25 
from your_table
order by whatever
0
source

Source: https://habr.com/ru/post/1756947/


All Articles