search

Home  >  Q&A  >  body text

Related usage and functions of the FOUND_ROWS() function in MariaDB 10

<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>
P粉670838735P粉670838735484 days ago476

reply all(1)I'll reply

  • P粉883278265

    P粉8832782652023-08-29 09:48:52

    FOUND_ROWS returns the number of rows returned by the previous request (the entire select statement). It sounds like you just want:

    select count(1) from (select * From tipfirme limit 20) as T

    select found_rows(); Used alone does not always return 1; I suspect you are not testing what you want to test. If it follows select * from tipfirme limit 20; it does return the number of rows returned by the select (after limit, or before if you specified sql_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.

    reply
    0
  • Cancelreply