Name
FOUND_ROWS()
Synopsis
FOUND_ROWS()
Use this function in conjunction with the SQL_CALC_FOUND_ROWS
option of a
SELECT
statement to determine the number of rows an
SQL statement using a LIMIT
clause would have
generated without the limitation. There are no arguments for the
function. It’s available as of version 4 of MySQL. Here is an
example:
SELECT SQL_CALC_FOUND_ROWS name_first, name_last, telephone_home, DATEDIFF(now( ), last_review) AS 'Days Since Last Review' FROM employees WHERE dept = 'sales' ORDER BY last_review DESC LIMIT 10; SELECT FOUND_ROWS();
In the first statement, we retrieve a list of sales people to review, limited to the 10 who have gone the longest without a performance review. In the second SQL statement, we’re getting a total count of how many employees there are to review in the sales department.
Get MySQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.