Solved

Count(*) from multiple tables

Posted on 2007-03-23
4
210 Views
Last Modified: 2010-03-19
How do i pull a count(*) from 6 tables. Each has a Account ID that should be matched.

Account ID table1 table2 table3 table3 ...
-------------------------------------------------
0001          10         21       7         8
0004 .................
0
Comment
Question by:bender007
  • 2
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 18783142
Select AccountID,
          COUNT(*) Table1Count,
          (Select COUNT(*) From Table2 t2 Where t1.AccountID = t2.AccountID) Table2Count,
          (Select COUNT(*) From Table3 t3 Where t1.AccountID = t3.AccountID) Table3Count,
...
          (Select COUNT(*) From Tablen tn Where t1.AccountID = tn.AccountID) TablenCount
From Table2 t1
Group By t1.AccountID

0
 

Author Comment

by:bender007
ID: 18783168
What is Table1Count .... I am confused.
0
 

Author Comment

by:bender007
ID: 18783234
Ok its an alias, I got that ,  why start from Table2 ?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 18783564
>>why start from Table2 ?<<
Look again.  I started with Table1.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

709 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now