954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Trying to get row count from multiple tables

I have around 20 tables in my database. I want to count every row of every table using COUNT and get a total. I have tried doing a separate select statement for each table then using UNION but I cannot find a way to join the results to get just one total number. Another thing I want to mention is that a lot of the tables are empty, but will later have data in them. Could someone please give me an idea of what kind of query to do? Thanks.

Tekkno
Junior Poster
134 posts since Apr 2009
Reputation Points: 12
Solved Threads: 7
 

does this work?

SELECT COUNT(x.*) AS countx, COUNT(y.*) AS county, COUNT(z.*) AS countz, (countx+county+countz) AS total FROM mytable1 AS x, mytable2 AS y, mytable3 AS x


Edit: No. but the following works

SELECT countx+county+countz AS total FROM
(SELECT COUNT( * ) AS countx FROM table1) AS x, 
(SELECT COUNT( * ) AS county FROM table2) AS y,
(SELECT COUNT( * ) AS countz FROM table3) AS z
jakesee
Junior Poster
130 posts since Jul 2008
Reputation Points: 21
Solved Threads: 5
 

Worked great jake, thank you very much.

Tekkno
Junior Poster
134 posts since Apr 2009
Reputation Points: 12
Solved Threads: 7
 

SELECT (COUNT(x.*)+COUNT(y.*)+COUNT(z.*)) AS total FROM mytable1,mytable2, mytable3

Oca13th
Newbie Poster
1 post since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You