MySQL provides a very useful query parameter for querying by page.

Source: Internet
Author: User

The SELECT statement of MySQL has the following parameter: SQL _CALC_FOUND_ROWS. This parameter can be used with the function FOUND_ROWS () provided by MySQL.

When we use LIMIT ?,? During paging query, only the records you want are returned. For example, if LIMIT 10 is used, the first 10 records are returned. However, we do not know how many records are involved in the entire query, you need to resend a query without LIMIT to obtain the number of records for paging.

The use of the FOUND_ROWS () function does not need to be so troublesome. Try to execute the following SQL statement:

Mysql> SELECT SQL _CALC_FOUND_ROWS * FROM tbl_name-> WHERE id> 100 LIMIT 10;
Mysql> SELECT FOUND_ROWS ();

This method is feasible in the command line mode of MySQL, and it is also feasible to execute it in Navicat, but it is wrong to execute it separately.

In addition, the FOUND_ROWS function can only be executed once after the SQL statement is executed. If it is executed again, 1 is returned.

Finally, this parameter and function are unique to MySQL. If the application needs to support multiple databases, we recommend that you do not use them.

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.