Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 932
Caffeinated Avatar asked Nov 25 '14 17:11

Caffeinated


People also ask

How do I select top 10 rows in MySQL?

Here's the SQL query to select top 10 distinct rows using DISTINCT keyword. mysql> select distinct * from sales limit 10; Hopefully, now you can easily select top N rows in MySQL. Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards.

How do I select the first 10 rows in MySQL?

To select first 10 elements from a database using SQL ORDER BY clause with LIMIT 10. Insert some records in the table using insert command. Display all records from the table using select statement. Here is the alternate query to select first 10 elements.


1 Answers

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
like image 132
Mureinik Avatar answered Sep 19 '22 12:09

Mureinik