Home >Database >Mysql Tutorial >How to query the number of rows in a table in mysql
Mysql method to query the number of rows in a table: 1. Use the "SELECT" statement to query all data in the specified table; 2. Use the COUNT() function to count the number of rows in the query results. The syntax is "SELECT COUNT (*) FROM table_name;".
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
The number of rows in mysql query table
1. Get the number of rows in a single table
SELECT COUNT(*) FROM table_name;
2. Get the number of rows in multiple tables (you can use the UNION operator to combine the result set returned by each SELECT statement)
SELECT 'tablename1' tablename, COUNT(*) rows FROM table_name1UNION SELECT 'tablename2' tablename, COUNT(*) rows FROM table_name2;
3. Get all tables of a database The number of rows (the information_schema method is sometimes inaccurate)
use information_schema; select table_name,table_rows from tables where TABLE_SCHEMA = 'db.name' order by table_rows desc;
[Related recommendations: mysql video tutorial]
The above is the detailed content of How to query the number of rows in a table in mysql. For more information, please follow other related articles on the PHP Chinese website!