Found_rows ()
It is often possible to return rows with limit restrictions in SELECT statements. Sometimes you may want to know how many rows will be returned without a limit, but you do not want to execute the same statement again. Then, include the Sql_calc_found_rows option in the Select query and then execute Found_rows ().
For example, the first 10 rows of a table need to be taken out, and the total number of matching conditions needs to be removed. This is common in some page-flipping operations
MySQL>SELECT* from tbl_nameWHERE>100 mysql>SELECT found_rows ()
Indicates that:
After the previous query, you only need to use found_rows () to get the total number of queries, which is the number of results after the limit is thrown out
The first SQL inside the sql_calc_found_rows can not be omitted, it indicates the need to obtain the number of results, but also the use of found_rows () function behind the foreshadowing.
The second select returns the first select if there is no limit when the number of rows returned,
If the sql_calc_found_rows option is not used in the previous statement , Found_rows () returns the number of rows actually returned by the previous statement.
found_rows () The resulting number is temporary, and execution of the next statement will be invalidated . If you want this number, you need to save it.
MySQL>SELECT* from ...; MySQL>SET@rows = found_rows ();
If you use SELECT Sql_calc_found_rows,mysql, you must calculate the number of rows for all result sets. Despite this,
It's much faster than executing a query that doesn't use limit again, because then the result set returns to the client's
mysql-function Found_rows ()