Mysql found_row () Usage Details, mysqlfound_row
Mysql found_row () is used to obtain the number of rows obtained by the Select statement. For example, a SQL statement needs to retrieve the first 10 rows of a table and the total number of rows that meet the conditions. This article introduces the usage of mysql found_row. For more information, see.
The FOUND_ROWS () function is added to mysql 4.1. The description of this function is as follows:
Copy codeThe Code is as follows:
For a SELECT with a LIMIT clause, the number of rows that wocould be returned were there no LIMIT clause
A select statement may include a LIMIT clause to restrict the number of rows the server returns to the client. in some cases, it is desirable to know how to handle rows the statement wowould have returned without the LIMIT, but without running the statement again. to obtain this row count, include a SQL _CALC_FOUND_ROWS option in the SELECT statement, and then invoke FOUND_ROWS () afterward:
For example, a SQL statement needs to retrieve the first 10 rows of a table and the total number of rows that meet the conditions. This is common in some paging operations.
SELECT SQL_CALC_FOUND_ROWS * FROM tbl_nameWHERE id > 100 LIMIT 10;
After the previous query, you only need to use FOUND_ROWS () to obtain the total number of queries. This number is the number of results after the LIMIT is dropped:
SELECT FOUND_ROWS();
The SQL _CALC_FOUND_ROWS In the first SQL statement cannot be omitted. It indicates the number of results to be obtained, which is also the foundation for using the FOUND_ROWS () function later.
A solution to the problems encountered during use
When writing MySQL pages, we found that FOUND_ROWS always returns 1, and there are more than 1 actual record. The SQL statement is as follows:
select sql_calc_found_rows * from actionlist where A_ID > 0 limit 10;select FOUND_ROWS();
Search for Chinese documents online. Find the cause of the problem in English
The preceding problem occurs when MySQL Workbech is used. Use MySQL Command Line Client to execute the same SQL statement and return value OK!
If you encounter the same problem, try it!