Skip to content

SQL_CALC_FOUND_ROWS

SELECT SQL_CALC_FOUND_ROWS * FROM Customers LIMIT 5;
SELECT FOUND_ROWS();
+----------+-----------+----------+
| CustomerID | FullName | Country |
+----------+-----------+----------+
| 1 | John Doe | USA |
| 2 | Jane Doe | Australia|
| 3 | Sam Bane | UK |
| 4 | Ben Lane | Canada |
| 5 | Anna Mae | Ireland |
+----------+-----------+----------+
20

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.