Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL - How to count all rows per table in one query

Tags:

sql

mysql

count

Is there a way to query the DB to find out how many rows there are in all the tables?

i.e.

table1 1234 table2 222 table3 7888 

Hope you can advise

like image 471
Lee Avatar asked Apr 22 '10 15:04

Lee


People also ask

How do I count the number of rows returned by a query in MySQL?

The COUNT() function is an aggregate function that returns the number of rows in a table. The COUNT() function allows you to count all rows or only rows that match a specified condition. The COUNT() function has three forms: COUNT(*) , COUNT(expression) and COUNT(DISTINCT expression) .

How do I count rows in MySQL by group?

So, if you want to count quantity of groups, not quantity of elements in each group, and return duplicate value to every group record in result table, you should use OVER() clause on you'r count function.

What is Row_count () in MySQL?

In MySQL the ROW_COUNT() function is used to return the number of rows affected by the previous SQL statement. If the previous statement was not one that could potentially change data rows or you can say, it wasn't an INSERT, UPDATE, DELETE or other such statement this function will return -1.

How do I find the number of rows in each table of the schema?

This can be achieved by using the following query. SELECT table_schema, SUM(row_count) AS total_rows FROM ( SELECT table_schema, count_rows_of_table(table_schema, table_name) AS row_count FROM information_schema.


1 Answers

SELECT      TABLE_NAME,      TABLE_ROWS  FROM      `information_schema`.`tables`  WHERE      `table_schema` = 'YOUR_DB_NAME'; 
like image 120
great_llama Avatar answered Sep 23 '22 01:09

great_llama