Trying to get row count from multiple tables

Thread Solved

Join Date: Apr 2009
Posts: 64
Reputation: Tekkno is an unknown quantity at this point 
Solved Threads: 1
Tekkno Tekkno is offline Offline
Junior Poster in Training

Trying to get row count from multiple tables

 
0
  #1
Apr 18th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 95
Reputation: jakesee is an unknown quantity at this point 
Solved Threads: 4
jakesee jakesee is offline Offline
Junior Poster in Training

Re: Trying to get row count from multiple tables

 
1
  #2
Apr 18th, 2009
does this work?

  1. 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

  1. SELECT countx+county+countz AS total FROM
  2. (SELECT COUNT( * ) AS countx FROM table1) AS x,
  3. (SELECT COUNT( * ) AS county FROM table2) AS y,
  4. (SELECT COUNT( * ) AS countz FROM table3) AS z
Last edited by peter_budo; Apr 19th, 2009 at 5:05 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 64
Reputation: Tekkno is an unknown quantity at this point 
Solved Threads: 1
Tekkno Tekkno is offline Offline
Junior Poster in Training

Re: Trying to get row count from multiple tables

 
0
  #3
Apr 18th, 2009
Worked great jake, thank you very much.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for MySQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC