Related usage and functions of the FOUND_ROWS() function in MariaDB 10
P粉670838735
2023-08-28 17:39:42
<p>I have a function that needs the number of rows returned by a select statement. After some searching, I found the FOUND_ROWS() function. But I don't think it works: </p>
<pre class="brush:php;toolbar:false;">SELECT * FROM tipfirme LIMIT 20;
SELECT FOUND_ROWS();</pre>
<p>Because it always returns 1 as the value found. </p>
<p>However, if I run it in one line, it works. </p>
<pre class="brush:php;toolbar:false;">SELECT FOUND_ROWS() FROM (SELECT * FROM tipfirme LIMIT 20) as T</pre>
<p>Am I doing something wrong or is there something wrong with this function? </p>
FOUND_ROWS returns the number of rows returned by the previous request (the entire select statement). It sounds like you just want:
select found_rows();
Used alone does not always return 1; I suspect you are not testing what you want to test. If it followsselect * from tipfirme limit 20;
it does return the number of rows returned by the select (after limit, or before if you specifiedsql_calc_found_rows in the previous select
).SELECT FOUND_ROWS() FROM (SELECT * FROM tipfirme LIMIT 20) as T
is not the result you want; it will return the same number of rows as the subquery returns, and each row There will be the number of rows returned by the previously executed select, regardless of the number of rows in the subquery.