从 MySQL 中的第 n 条记录等中选择 [英] Select from nth record and so on in MySQL

查看:56
本文介绍了从 MySQL 中的第 n 条记录等中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<块引用>

可能的重复:
MySQL LIMIT/OFFSET:获取除第一个 X 以外的所有记录

好的,我确实有一个这样的 sql 查询

SELECT * FROM `profile_registry` LIMIT 3, 100

现在我想要的是从第三行开始获取数据,依此类推.

上面的代码有效,但问题是 LIMIT 可以通过使用一两个参数来使用.

唯一一个参数的条件是它只控制返回多少行.

两个参数的条件是第一个参数定义起点,第二个参数定义返回多少条记录.

现在我的问题是我无法将第二个参数设置为只有 100,因为我们不知道将来会有多少条记录.我想要的是返回从某一行开始的所有记录,而不设置返回行数的限制.

解决方案

来自文档

一个>:

<块引用>

检索从某个偏移量到结果末尾的所有行设置,您可以使用一些大数字作为第二个参数.这语句检索从第 96 行到最后一行的所有行:

SELECT * FROM tbl LIMIT 95,18446744073709551615;

Possible Duplicate:
MySQL LIMIT/OFFSET: get all records except the first X

Ok I do have a sql query like this

SELECT * FROM `profile_registry` LIMIT 3, 100

now what i want here is to get data starting from the 3rd row and so on.

The code above works but the problem is the LIMIT can be used by using one or two parameters.

the condition of the only one parameter is it only controls how many rows to return.

the condition of the two parameters is the first parameter defines the starting point and the second parameter defines how many records to return.

Now my problem here is I can't set the second parameter as if its only 100 as we don't know how many records will be in the future. What I want is to return all the records starting on a certain row without setting a limit on how many rows to return.

解决方案

From the documentation:

To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter. This statement retrieves all rows from the 96th row to the last:

SELECT * FROM tbl LIMIT 95,18446744073709551615;

这篇关于从 MySQL 中的第 n 条记录等中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆