| | |
Trying to get row count from multiple tables
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Apr 2009
Posts: 64
Reputation:
Solved Threads: 1
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.
•
•
Join Date: Jul 2008
Posts: 95
Reputation:
Solved Threads: 4
does this work?
Edit: No. but the following works
sql Syntax (Toggle Plain Text)
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
sql Syntax (Toggle Plain Text)
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
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.
![]() |
Similar Threads
- Deleting records from 2 tables based on checkbox (PHP)
- Filter/Update Multiple Records (PHP)
- Comparing Two Datasets (VB.NET)
- Hi guys please clear my doubt. (ASP.NET)
- row count (MS SQL)
- Schedule Repeat events (PHP)
- php drop down menu to search multiple sql tables (PHP)
- Query multiple tables with duplicate data (MySQL)
Other Threads in the MySQL Forum
- Previous Thread: putting a image hyperlink in mySQL
- Next Thread: guestbook
| Thread Tools | Search this Thread |
Tag cloud for MySQL
"use" 1 agplv3 alfresco amazon api artisticlicense bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm data database design developer development distinct drupal dui ec2 email enter error eudora form foss gartner gnu government greenit groklaw groupware hiring hyperic images joebrockmeier journalism keyword keywords laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple music mysql mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource operand pdf penelope php priceupdating query remove reorderingcolumns results resultset saas search select simpledb sourcecode spotify sql statement syntax techsupport thunderbird transparency virtualization





