Get the App
SLTechnology News&Howtos  ›  Database  › 

The function of calculating the number of rows affected by sql statements in mysql

Shulou Source: shulou.com Published: 2022-06-01 07:07:17 09月21日 Update

It is often possible to use LIMIT to limit the number of rows returned in a SELECT statement. Sometimes you may want to know how many rows would be returned without LIMIT, but you don't want to execute the same statement again. Then, include the SQL_CALC_FOUND_ROWS option in the SELECT query, and then execute FOUND_ROWS (): mysql > SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name

-> WHERE id > 100 LIMIT 10

The second SELECT of mysql > SELECT FOUND_ROWS () will return the number of rows returned by the first SELECT if there is no LIMIT. If the SQL_CALC_FOUND_ROWS option is not used in the previous statement, FOUND_ROWS () will return the actual number of rows returned by the previous statement. The number obtained by FOUND_ROWS () is temporary, and the execution of the next statement will fail. If you want this number, save it: mysql > SELECT SQL_CALC_FOUND_ROWS * FROM.

Mysql > SET @ rows = FOUND_ROWS (); if you use SELECT SQL_CALC_FOUND_ROWS,MySQL, you must count the rows of all result sets. Still, it's much faster than executing another query that doesn't use LIMIT, because the result set will be returned to the client. [@ more@]

Tags: Statement number result query same actual customer sometimes end subcontract limit function influence Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Xiaomi Docker MariaDB Huawei