Home > Database > Mysql Tutorial > mysql limit 实例详解

mysql limit 实例详解

WBOY
Release: 2016-06-01 09:57:10
Original
1033 people have browsed it

mysql中limit子句标准语法为:

<code class="language-sql">SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset
</code>
Copy after login


从上面我们可以看出limit有如下几种用法:

第一种使用情况:

<code class="language-sql">select * from table limit 5</code>
Copy after login

取前五条

第二种使用情况:

<code class="language-sql">select * from table limit 0,5</code>
Copy after login

从第1-5条,这里用了一个offset参数,这个参数是从0开始计数的。如果取值为1,则表示从第2条开始。后面的5仍然是条数。

第三种使用情况:

<code class="language-sql">select * from table limit 5 OFFSET 0</code>
Copy after login

作用还是取第1-5条,只是用了OFFSET这个子句配合limit一起使用。
 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template