MySQL中Select Limit使用方法
admin
2023-05-20 01:02:15
0

本篇文章给大家主要讲的是关于MySQL中Select Limit使用方法的内容,感兴趣的话就一起来看看这篇文章吧,相信看完MySQL中Select Limit使用方法对大家多少有点参考价值吧。

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

LIMIT takes one or two numeric arguments,which must both be nonnegative integer constants, with these exceptions:

limit后面可以跟1或2个×××参数,必须是非负整数常量。

Within prepared statements, LIMIT parameters can be specified using? placeholder markers.

在预编译语句中,limit参数可使用?占位符。

Within stored programs, LIMIT parameters can be specified usinginteger-valued routine

parameters or local variables.

With two arguments, the first argumentspecifies the offset of the first row to return, and the second specifies themaximum number of rows to return. The offset of theinitial row is 0 (not 1):

SELECT * FROM tbl LIMIT5,10; # Retrieve rows 6-15

To retrieve all rows from a certain offsetup 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 thelast:

SELECT * FROM tbl LIMIT95,18446744073709551615;

With one argument, the value specifies thenumber of rows to return from the beginning of the result set:

SELECT * FROM tbl LIMIT5; # Retrieve first 5 rows,返回前5行

In other words, LIMIT row_count isequivalent to LIMIT 0, row_count.

For prepared statements, you can useplaceholders. The following statements will return one row

from the tbl table:

SET @a=1;

PREPARE STMT FROM 'SELECT* FROM tbl LIMIT ?';

EXECUTE STMT USING @a;

The following statements will return thesecond to sixth row from the tbl table:

SET @skip=1; SET@numrows=5;

PREPARE STMT FROM 'SELECT* FROM tbl LIMIT ?, ?';

EXECUTE STMT USING @skip,@numrows;

For compatibility with PostgreSQL, MySQLalso supports the LIMIT row_count OFFSET offset

syntax.

If LIMIT occurs within a subquery and alsois applied in the outer query, the outermost LIMIT takes

precedence. For example, the followingstatement produces two rows, not one:

(SELECT ... LIMIT 1) LIMIT 2;

以上关于MySQL中Select Limit使用方法详细内容,对大家有帮助吗?如果想要了解更多相关,可以继续关注我们的行业资讯板块。

相关内容

热门资讯

男子手机号被当成迪卡侬官方售后... 7月24日,浙江宁波的王先生发帖称,自己的手机号被设置成迪卡侬售后服务热线,两年间陆续有上百个陌生电...
家长带孩子打卡大连“海底隧道”... 近日,有网友在社交平台发布的图片显示,大连湾海底隧道上方采用透明玻璃顶棚,可以看见湛蓝海水与海底生物...
淋浴房角落发霉怎么处理 1、先清除掉表面的灰尘和脏东西。2、再将稀释后的清洗剂涂刷或喷洒在黄斑和污迹的表面,用白色的纯棉布或...
淋浴房玻璃门修理 1、如果是玻璃门的推拉活动不够灵活的话,修理方法非常简单,可以蹲下看看底部的推拉条和门之间是不是有错...
淋浴房玻璃门滑轮修理 1、发生玻璃门摆动,可用棍棒调整滚筒,因为它沿轨道移推拉门动。主要是看小孔在门的顶部和底部附近的辊,...
液晶电视有音黑屏什么原因 1、电视机距墙太近导致机身温度太高,电视机身温度太高无法正常的使用。2、可能是电视机硬件出现了故障,...
装修后墙面翻新有必要吗 有必要的。原因有1、墙面在受到环境和人为破换,原建筑材料本身特性等因素影响,出现各种墙面残旧问题,如...
牛蛙抗生素超标5倍,真把消费者... 文 | 心 冥深夜嗦蛙一时爽,一看检测报告“火葬场”。近日,“抗生素牛蛙”冲上热搜,给人看得一哆嗦,...
男子外出喝酒后深夜被人送回,家... 2025年8月21日,甘肃陇西县47岁男子张某某外出与人喝酒,其父母多次电话寻人,电话多由他人接听。...
安德烈·科尔图诺夫:当资本主义... 【文/观察者网专栏作者 安德烈·科尔图诺夫】 两千年前,蒙爱圣徒约翰警示所有罪人和无信之人:“拒绝把...