mysql-function Found_rows ()

Source: Internet
Author: User

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 ()

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.