
- 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
Can we get total number of rows in a MySQL database?
To get the total number of rows in a MySQL database, you can use aggregate function SUM() along with inbuilt column TABLE_ROWS from INFORMATION_SCHEMA.TABLES.
The syntax is as follows−
SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = database();
Let’s say we are using the database with the name ‘sample’.
Now we will get the total number of rows in a MySQL database−
mysql> SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = database();
This will produce the following output−
+-----------------+ | SUM(TABLE_ROWS) | +-----------------+ | 2043 | +-----------------+ 1 row in set (22.11 sec)
- Related Articles
- How can we get the total number of rows affected by MySQL query?
- Get total number of rows while using LIMIT in MySQL?
- How can we get all the unique rows in MySQL result set?
- How can we write PHP script to get the list of MySQL database?
- How can we use MySQL SELECT statement to count number of rows in a table?
- In MySQL, how can we get the number code of a particular character?
- Finding total number of rows of tables across multiple databases in MySQL?
- How can we get the list of tables in a particular database from MySQL Server command line?
- Get at least x number of rows in MySQL?
- Get the number of rows in a particular table with MySQL
- Easiest way to get number of rows in a MySQL table?
- How can we get the structure of a MySQL view as we can get the structure of a MySQL table?
- How can we get the definition of a MySQL view as we can get the definition of a MySQL table?
- In MySQL, how we can get the total value by category in one output row?
- How can we use a MySQL stored function in a database query?

Advertisements