This question already has an answer here:
I would like to know how to Count the TOTAL number of rows in the tables of a database. For example, I have 3 tables in a database called:
Table 1: 5 rows
Table 2: 4 rows
Table 3: 3 rows
So the output should be: 12 rows.
I know how to count rows in a specific table. Is there something to loop here?
Thanks.
</div>
SELECT sum(cnt) AS overall_cnt
FROM (
SELECT count(*) AS cnt FROM table1
UNION ALL
SELECT count(*) AS cnt FROM table2
UNION ALL
SELECT count(*) AS cnt FROM table3
) AS foo
SELECT sum(TABLE_ROWS)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME IN ('table1', 'table2', 'table3');