mysql found_row of in detail

  • 2021-01-14 06:46:14
  • OfStack

mysql found_row() is used to get the number of rows obtained by Select. For example, if a segment sql needs to fetch the first 10 rows of a table, it also needs to fetch the total number of rows that meet the criteria. mysql found_row This article introduces the usage of mysql found_row. If you are interested, please refer to 1 below.

The function FOUND_ROWS() was added in ES11en 4.1. The description for this function is as follows:


For a SELECT with a LIMIT clause, the number of rows that would 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 many rows the statement would 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 segment sql needs to fetch the first 10 rows of a table, and at the same time it needs to fetch the total number of qualified rows. This is common in some paging operations


SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name
WHERE id > 100 LIMIT 10;

After the previous query, you just need to use FOUND_ROWS() to get the total number of queries, which is the number of results after dropping LIMIT:


SELECT FOUND_ROWS();

In the first sql, SQL_CALC_FOUND_ROWS cannot be omitted. It indicates the number of results that need to be obtained, and it is also the preparation for using FOUND_ROWS() function later.

Write down the solutions to the problems encountered in the first use

Write MySQL paging found FOUND_ROWS always return 1, never check 1 the actual record. The SQL statement reads as follows:


select sql_calc_found_rows * from actionlist where A_ID > 0 limit 10;
select FOUND_ROWS();

Searching Chinese data online, not solved. Find the cause of the problem in English

Using MySQL, Workbech presents the above problems. MySQL Command Line Client SQL MySQL Command Line Client

If you have the same problem, try it!


Related articles: