20

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

Mureinik
  • 297,002
  • 52
  • 306
  • 350
Caffeinated
  • 11,982
  • 40
  • 122
  • 216
  • 1
    possible duplicate of [ROW\_NUMBER() in MySQL](http://stackoverflow.com/questions/1895110/row-number-in-mysql) – tadman Nov 25 '14 at 17:49
  • 5
    MariaDB is based on *MySQL*, not *MS SQL*. – tadman Nov 25 '14 at 17:49
  • @tadman - ah, I mixed it up then, apologies. thanks ! – Caffeinated Nov 25 '14 at 17:52
  • 1
    The [MySQL 5.6 documentation](http://dev.mysql.com/doc/refman/5.6/en/) is pretty thorough and has a function index. It's something any developer should have bookmarked and at the ready. If you're ever curious if a function exists, look there first. Stack Overflow is a good second place to check when you're stumped. – tadman Nov 25 '14 at 17:54

2 Answers2

34

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
Mureinik
  • 297,002
  • 52
  • 306
  • 350
2

use LIMIT 10 at the end of your statement.

See the MySQL SELECT documentation.

declension
  • 4,110
  • 22
  • 25