Home > Database > Mysql Tutorial > How to query the number of rows in a table in mysql

How to query the number of rows in a table in mysql

青灯夜游
Release: 2021-12-31 18:07:36
Original
23606 people have browsed it

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;".

How to query the number of rows in a table in mysql

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;
Copy after login

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;
Copy after login

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;
Copy after login

[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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template