SQL_CALC_FOUND_ROWS
SQL_CALC_FOUND_ROWS is a command used in MySQL to calculate the number of rows a SELECT statement would return without LIMIT clause applied. It allows MySQL to return the number of fetched rows even when you're using a LIMIT clause.
Example
SELECT SQL_CALC_FOUND_ROWS * FROM Customers LIMIT 5;SELECT FOUND_ROWS();
Output
+----------+-----------+----------+| CustomerID | FullName | Country |+----------+-----------+----------+| 1 | John Doe | USA || 2 | Jane Doe | Australia|| 3 | Sam Bane | UK || 4 | Ben Lane | Canada || 5 | Anna Mae | Ireland |+----------+-----------+----------+
20
Explanation
In this example, SQL_CALC_FOUND_ROWS is used to calculate the total number of rows in the Customers table regardless of the LIMIT clause. The first query returns the first 5 rows from the Customers table. The second query, SELECT FOUND_ROWS(), returns the total number of rows in the table. In the provided output, the function FOUND_ROWS() returns 20, indicating there are 20 total rows in the Customers table.