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

Caffeinated picture Caffeinated · Nov 25, 2014 · Viewed 36.9k times · Source

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

Answer

Mureinik picture Mureinik · Nov 25, 2014

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