Bookmark and Share
SQL_CALC_FOUND_ROWS and FOUND_ROWS()
(Publish Date: 2009-8-26 11:58am, Total Visits: 5247, Today: 2, This Week: 6, This Month: 25)

SQL_CALC_FOUND_ROWS and FOUND_ROWS() can be useful in situations when you want to restrict the number of rows that a query returns, but also determine the number of rows in the full result set without running the query again. An example is a Web script that presents a paged display containing links to the pages that show other sections of a search result. Using FOUND_ROWS() allows you to determine how many other pages are needed for the rest of the result.

mysql> SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name
    -> WHERE id > 100 LIMIT 10;
mysql> SELECT FOUND_ROWS();

The second SELECT returns a number indicating how many rows the first SELECT 
would have returned had it been written without the LIMIT clause.
In the absence of the SQL_CALC_FOUND_ROWS  option in the most recent successful
SELECT statement, FOUND_ROWS() returns the number of rows in the result set
returned by that statement. If the statement includes a LIMIT clause, FOUND_ROWS()
returns the number of rows up to the limit. For example, FOUND_ROWS() returns 10
or 60, respectively, if the statement includes LIMIT 10 or LIMIT 50, 10.
http://dev.mysql.com/doc/refman/5.1/en/information-functions.html
Important:
FOUND_ROWS() is not replicated reliably using statement-based replication.
Starting with MySQL 5.1.23, this function is automatically replicated using row-based replication.