snipt

Ctrl+h for KB shortcuts

SQL

Use found_rows() in MySQL

1
2
3
4
// use found_rows() as a sql function
mysql> SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name
    -> WHERE id > 100 LIMIT 10;
mysql> SELECT FOUND_ROWS();
https://snipt.net/embed/7f96bfa1e2c3e7c31588a310d9691404/
/raw/7f96bfa1e2c3e7c31588a310d9691404/
7f96bfa1e2c3e7c31588a310d9691404
sql
SQL
5
2019-08-24T20:08:25
True
False
False
/api/public/snipt/11548/
use-found_rows-in-mysql
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="o">//</span> <span class="n">use</span> <span class="n">found_rows</span><span class="p">()</span> <span class="k">as</span> <span class="n">a</span> <span class="k">sql</span> <span class="k">function</span> </span><span id="L-2"><a name="L-2"></a><span class="n">mysql</span><span class="o">&gt;</span> <span class="k">SELECT</span> <span class="n">SQL_CALC_FOUND_ROWS</span> <span class="o">*</span> <span class="k">FROM</span> <span class="n">tbl_name</span> </span><span id="L-3"><a name="L-3"></a> <span class="o">-&gt;</span> <span class="k">WHERE</span> <span class="n">id</span> <span class="o">&gt;</span> <span class="mi">100</span> <span class="k">LIMIT</span> <span class="mi">10</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="n">mysql</span><span class="o">&gt;</span> <span class="k">SELECT</span> <span class="n">FOUND_ROWS</span><span class="p">();</span> </span></pre></div> </td></tr></table>
database, db, mysql, select