Collections:
FOUND_ROWS() - Row Count from Last SELECT Statement
How to obtain the number of rows found by the last SELECT statement using the FOUND_ROWS() function?
✍: FYIcenter.com
FOUND_ROWS() is a MySQL built-in function that
returns the number of rows found by the last SELECT statement.
For example:
SELECT help_topic_id, name FROM mysql.help_topic; -- +---------------+------------------------------------+ -- | help_topic_id | name | -- +---------------+------------------------------------+ -- | 65 | ! | -- | 47 | != | -- | 140 | % | -- | 238 | & | -- | 137 | * | -- ... -- +---------------+------------------------------------+ 682 rows in set (0.01 sec) SELECT FOUND_ROWS(); -- +--------------+ -- | FOUND_ROWS() | -- +--------------+ -- | 682 | -- +--------------+
If the LIMIT clause is used in the SELECT statement, you need to use the "SELECT SQL_CALC_FOUND_ROWS" statement to give you the correct total rows found value. For example:
SELECT help_topic_id, name FROM mysql.help_topic LIMIT 3; -- +---------------+------+ -- | help_topic_id | name | -- +---------------+------+ -- | 65 | ! | -- | 47 | != | -- | 140 | % | -- +---------------+------+ SELECT FOUND_ROWS(); -- +--------------+ -- | FOUND_ROWS() | -- +--------------+ -- | 3 | -- +--------------+ SELECT SQL_CALC_FOUND_ROWS help_topic_id, name FROM mysql.help_topic LIMIT 3; -- +---------------+------+ -- | help_topic_id | name | -- +---------------+------+ -- | 65 | ! | -- | 47 | != | -- | 140 | % | -- +---------------+------+ SELECT FOUND_ROWS(); -- +--------------+ -- | FOUND_ROWS() | -- +--------------+ -- | 682 | -- +--------------+
Reference information of the FOUND_ROWS() function:
FOUND_ROWS(): count Returns the number of rows found by the last SELECT statement. Arguments, return value and availability: count: Return value. The number of rows found by the last SELECT statement. Available since MySQL 4.0.
⇒ ICU_VERSION() - ICU (International Components for Unicode) Version
⇐ DATABASE() - Name of Current Database
2025-04-11, 638🔥, 0💬
Popular Posts:
How To Get the Definition of a Stored Procedure Back in SQL Server Transact-SQL? If you want get the...
What is dba.FYIcenter.com Website about? dba.FYIcenter.com is a Website for DBAs (database administr...
How To Convert Binary Strings into Integers in SQL Server Transact-SQL? Binary strings and integers ...
How To Query Tables and Loop through the Returning Rows in MySQL? The best way to query tables and l...
Where to find answers to frequently asked questions on CREATE, ALTER and DROP Statements in MySQL? H...