gpt4 book ai didi

php - 如何选择mysql中的最后一行

转载 作者:行者123 更新时间:2023-11-29 01:11:31 24 4
gpt4 key购买 nike

我创建了一个至少包含 100 行的表格。当我想检索一个元素时,我在下面执行以下代码。这将返回 id 在 11 到 28 之间的项目。我的目标是能够回显最后一个项目,即 28。我如何在 mysql 上实现这个?

SELECT names
FROM item_list
WHERE id >= 10
LIMIT 18

最佳答案

您的原始查询实际上将返回第 10 行到第 27 行。

| ID |------| 10 || 11 || 12 || 13 || 14 || 15 || 16 || 17 || 18 || 19 || 20 || 21 || 22 || 23 || 24 || 25 || 26 || 27 |

To get the 28th row, you can use

WHERE id >= 10 
LIMIT 18, 1

See a demo

或者只是

LIMIT 27, 1

See a demo

The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement.

 SELECT * FROM tbl LIMIT 5,10;  # Retrieve rows 6-15
SELECT * FROM tbl LIMIT 95,18446744073709551615; # Retrieves rows from the 96th row to the last

In other words, LIMIT row_count is equivalent to LIMIT 0, row_count.

关于php - 如何选择mysql中的最后一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16920466/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com