In MariaDB how do I select the top 10 rows from a table?

77.6k views Asked by At

I just read online that MariaDB (which SQLZoo uses), is based on MySQL. So I thought that I can use ROW_NUMBER() function

However, when I try this function in SQLZoo :

SELECT * FROM ( 
  SELECT  * FROM route
) TEST7
WHERE ROW_NUMBER()  < 10

then I get this error :

Error: FUNCTION gisq.ROW_NUMBER does not exist

2

There are 2 answers

1
Mureinik On BEST ANSWER

You can use the limit clause:

SELECT * FROM route LIMIT 10

This can, of course, be used on a sorted query too:

SELECT * FROM route ORDER BY some_field LIMIT 10
0
declension On

use LIMIT 10 at the end of your statement.

See the MySQL SELECT documentation.