MySQL 在 MariaDB 中,如何从表中选择前 10 行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27133374/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:12:18  来源:igfitidea点击:

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

mysqlsqlselectmariadbtop-n

提问by Coffee

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

我刚刚在网上读到 MariaDB(SQLZoo 使用的)是基于 MySQL 的。所以我想我可以使用 ROW_NUMBER() 函数

However, when I try this function in SQLZoo:

但是,当我在 SQLZoo 中尝试此功能时

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

then I get this error :

然后我收到此错误:

Error: FUNCTION gisq.ROW_NUMBER does not exist

错误:FUNCTION gisq.ROW_NUMBER 不存在

回答by Mureinik

You can use the limitclause:

您可以使用以下limit条款:

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

回答by declension

use LIMIT 10at the end of your statement.

LIMIT 10在语句的末尾使用。

See the MySQL SELECT documentation.

请参阅MySQL SELECT 文档