在 MySQL 中使用 LIMIT 和 OFFSET 时返回哪些行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10119291/
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 12:55:41  来源:igfitidea点击:

Which rows are returned when using LIMIT with OFFSET in MySQL?

mysql

提问by Arun Killu

In the query below:

在下面的查询中:

SELECT column 
FROM table
LIMIT 18 OFFSET 8

how many results will we get as output and from where to where?

我们将获得多少结果作为输出以及从哪里到哪里?

回答by Mosty Mostacho

It will return 18 results starting on record #9 and finishing on record #26.

它将返回从记录 #9 开始到记录 #26 结束的 18 个结果。

Start by reading the query from offset. First you offset by 8, which means you skip the first 8 results of the query. Then you limit by 18. Which means you consider records 9, 10, 11, 12, 13, 14, 15, 16....24, 25, 26 which are a total of 18 records.

首先从 读取查询offset。首先偏移 8,这意味着您跳过查询的前 8 个结果。然后限制为 18。这意味着您考虑记录 9、10、11、12、13、14、15、16.....24、25、26,总共 18 条记录。

Check thisout.

看看这个

And also the official documentation.

还有官方文档

回答by vineet

OFFSETis nothing but a keyword to indicate starting cursor in table

OFFSET只不过是表示表中起始光标的关键字

SELECT column FROM table LIMIT 18 OFFSET 8 -- fetch 18 records, begin with record 9 (OFFSET 8)

you would get the same result form

你会得到相同的结果表

SELECT column FROM table LIMIT 8, 18

visual representation (Ris one record in the table in some order)

视觉表示(R是表中按某种顺序的一条记录)

 OFFSET        LIMIT          rest of the table
 __||__   _______||_______   __||__
/      \ /                \ /
RRRRRRRR RRRRRRRRRRRRRRRRRR RRRR...
         \________________/
                 ||
             your result

回答by Mahesh Patil

You will get output from columnvalue 9 to 26 as you have mentioned OFFSETas 8

您将获得从column值 9 到 26 的输出,正如您提到OFFSET的 8