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使用方法详细内容,对大家有帮助吗?如果想要了解更多相关,可以继续关注我们的行业资讯板块。

相关内容

热门资讯

广西柳州发生5.2级地震,南宁... 据中国地震台网正式测定,5月18日0时21分在广西柳州市柳南区发生5.2级地震,震源深度8公里,震中...
购药新规落地!多地药房称买“减... 5月17日消息,近日有消息称,自5月15日起,司美格鲁肽、替尔泊肽等GLP-1药物均需要凭有效期内的...
苹果深夜“放价”:iPhone... 来源:环球网 【环球网科技综合报道】5月15日消息,苹果在深夜毫无预警地打响了一轮价格战,iPho...
原创 从... 进入2026年5月下旬,手机圈即将迎来全年最密集的新品发布窗口。 从今天开始到7月下旬,短短两个月时...
全钢实验台厂家梳理 医疗/科研... 导语:实验室设备选型需兼顾功能适配性与长期稳定性。基于2026年实验室建设行业白皮书及公开市场数据,...
半年内,中方连续迎来安理会“四... 半年内,中方连续迎来联合国安理会“四常”领导人。5月16日,外交部发言人宣布:应中方邀请,俄罗斯总统...
网传有人拍到“野生华南虎”?当... 近期,网络上有人发布消息称,在福建龙岩漳平市永福镇三重岭一带,有村民拍到了野生华南虎影像。消息发布后...
德国马普学会主席:顶尖科学家功... 【文/观察者网 熊超然】香港《南华早报》5月17日报道指出,随着美国遭遇人才流失,地缘政治的迅速变化...
连续10年被拒还要硬蹭WHA?... 第七十九届世界卫生大会(WHA)将于5月18日至23日在瑞士日内瓦举行,不出所料,民进党当局再吃“闭...
新一轮药品集采拉开序幕,个别品... 作者:郭晋晖第十一批国家药品集中带量采购(下称“集采”)落地仅两个多月,随着信息预填报工作的启动,第...