﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-神魂颠倒-文章分类-MySQL</title><link>http://www.blogjava.net/star/category/30597.html</link><description>学习笔记</description><language>zh-cn</language><lastBuildDate>Mon, 07 Apr 2008 01:15:15 GMT</lastBuildDate><pubDate>Mon, 07 Apr 2008 01:15:15 GMT</pubDate><ttl>60</ttl><item><title>LIMIT</title><link>http://www.blogjava.net/star/articles/191129.html</link><dc:creator>star</dc:creator><author>star</author><pubDate>Sun, 06 Apr 2008 15:47:00 GMT</pubDate><guid>http://www.blogjava.net/star/articles/191129.html</guid><wfw:comment>http://www.blogjava.net/star/comments/191129.html</wfw:comment><comments>http://www.blogjava.net/star/articles/191129.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/star/comments/commentRss/191129.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/star/services/trackbacks/191129.html</trackback:ping><description><![CDATA[<li>
<p>The <code class="literal">LIMIT</code> clause can be used to constrain the number of rows returned by the <code class="literal">SELECT</code> statement. <code class="literal">LIMIT</code> takes one or two numeric arguments, which must both be non-negative integer constants (except when using prepared statements). </p>
<p>With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1): </p>
<pre class="programlisting">SELECT * FROM tbl LIMIT 5,10;  # Retrieve rows 6-15
</pre>
<p>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: </p>
<pre class="programlisting">SELECT * FROM tbl LIMIT 95,18446744073709551615;
</pre>
<p>With one argument, the value specifies the number of rows to return from the beginning of the result set: </p>
<pre class="programlisting">SELECT * FROM tbl LIMIT 5;     # Retrieve first 5 rows
</pre>
<p>In other words, <code class="literal">LIMIT <em class="replaceable"><code>row_count</code></em></code> is equivalent to <code class="literal">LIMIT 0, <em class="replaceable"><code>row_count</code></em></code>. </p>
<p>For prepared statements, you can use placeholders. The following statements will return one row from the <code class="literal">tbl</code> table: </p>
<pre class="programlisting">SET @a=1;
PREPARE STMT FROM 'SELECT * FROM tbl LIMIT ?';
EXECUTE STMT USING @a;
</pre>
<p>The following statements will return the second to sixth row from the <code class="literal">tbl</code> table: </p>
<pre class="programlisting">SET @skip=1; SET @numrows=5;
PREPARE STMT FROM 'SELECT * FROM tbl LIMIT ?, ?';
EXECUTE STMT USING @skip, @numrows;
</pre>
<p>For compatibility with PostgreSQL, MySQL also supports the <code class="literal">LIMIT <em class="replaceable"><code>row_count</code></em> OFFSET <em class="replaceable"><code>offset</code></em></code> syntax. </p>
</li>
<p>(select&nbsp;*&nbsp;order&nbsp;by&nbsp;id LIMIT&nbsp;35,20)</p>
 <img src ="http://www.blogjava.net/star/aggbug/191129.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/star/" target="_blank">star</a> 2008-04-06 23:47 <a href="http://www.blogjava.net/star/articles/191129.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>