1
<code>select</code> <code>* </code><code>from</code> <code>table</code> <code>limit [offset,] </code><code>rows</code> <code>| </code><code>rows</code> <code>offset offset</code>
limit 子句可以被用于强制 select 语句返回指定的记录数。limit 接受一个或两个数字参数。参数必须是一个整数常量。如果给定两个参数,第一个参数指定第一个返回记录行的偏移量,第二个参数指定返回记录行的最大数目。初始记录行的偏移量是 0(而不是 1): 为了与 postgresql 兼容,mysql 也支持句法: limit # offset #。
2
3
4
5
6
7
8
9
<code>mysql> </code><code>select</code> <code>* </code><code>from</code> <code>table</code> <code>limit 5,10; // 检索记录行 6-15</code>
<code>//为了检索从某一个偏移量到记录集的结束所有的记录行,可以指定第二个参数为 -1:</code>
<code>mysql> </code><code>select</code> <code>* </code><code>from</code> <code>table</code> <code>limit 95,-1; // 检索记录行 96-</code><code>last</code><code>.</code>
<code>//如果只给定一个参数,它表示返回最大的记录行数目:</code>
<code>mysql> </code><code>select</code> <code>* </code><code>from</code> <code>table</code> <code>limit 5; //检索前 5 个记录行</code>
<code>//换句话说,limit n 等价于 limit 0,n。</code>