Mysql found_row () Usage Details, mysqlfound_row

Source: Internet
Author: User
Tags mysql command line

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.