How to use COUNT(*) to Get Record Count In MySQL
In this method, use various subqueries, i.e., one subquery for each individual table record count.
Syntax:
SELECT
(SELECT COUNT(*) FROM 'your_table_name1') AS table1Count,
(SELECT COUNT(*) FROM ' your_table_name2') AS table2Count;
Example:
The query calculates and displays the counts of records in the ‘article‘ and ‘gfg‘ tables. ‘articleCount‘ indicates the record count in the ‘article’ table, and ‘gfgCount‘ indicates the record count in the ‘gfg‘ table.
SELECT
(SELECT COUNT(*) FROM article) AS articleCount,
(SELECT COUNT(*) FROM gfg) AS gfgCount;
Output:
Explanation: By executing the query, it retrieves and displays the counts of records in the ‘article‘ and ‘gfg‘ tables. The ‘articleCount’ is the count of records in the ‘article‘ table, and ‘gfgCount’ is the count of records in the ‘gfg‘ table.
How to Get Record Count for All Tables in MySQL Database
In DBMS, counting records for all tables within a MySQL database is a fundamental requirement. Understanding the size and distribution of data across tables helps optimize database performance and provides insights into data utilization and growth patterns.
Row or record count means how many records are present in the database. Here we will discuss various methods to efficiently retrieve record counts from all tables within a MySQL database.