MySQL query to find the number of rows in the last query



For this, use the FOUND_ROWS in MySQL. Following is the syntax −

SELECT SQL_CALC_FOUND_ROWS TABLE_NAME FROM `information_schema`.tables WHERE TABLE_NAME LIKE "yourValue%" LIMIT yourLimitValue;

Here, I am using the database ‘web’ and I have lots of tables, let’s say which begins from DemoTable29. Let us implement the above syntax to fetch only 4 of such rows −

mysql> SELECT SQL_CALC_FOUND_ROWS TABLE_NAME FROM `information_schema`.tables WHERE TABLE_NAME LIKE "DemoTable29%" LIMIT 4;

This will produce the following output −

+--------------+ | TABLE_NAME | +--------------+ | demotable29 | | demotable290 | | demotable291 | | demotable292 | +--------------+ 4 rows in set (0.01 sec)

Here is the query to know the total rows from the last query. We used LIMI4, therefore only 4 rows were visible above −

mysql> select found_rows();

This will produce the following output −

+--------------+ | found_rows() | +--------------+ | 10           | +--------------+ 1 row in set (0.00 sec)
Updated on: 2019-09-27T06:51:16+05:30

289 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements