
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- MySQL Query to find tables modified in the last hour?
- MySQL query to find the average of rows with the same ID
- Query MySQL table and fetch rows posted before the last 3 days?
- How can we get the total number of rows affected by MySQL query?
- MySQL query to find the number of occurrences from two columns?
- Which PHP function is used to give the number of rows affected by MySQL query?
- MySQL query to count rows in multiple tables
- MySQL query to select too many rows?
- MySQL query to select multiple rows effectively?
- How to get number of rows in a table without using count(*) MySQL query?
- Create a MySQL stored procedure that counts the number of rows gets affected by MySQL query?
- MySQL query to multiply values of two rows and add the result
- MySQL query to sum up values of rows and sort the result?
- MongoDB query to find last object in collection?
- MySQL query to search within the last 5 characters in a column?

Advertisements