Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Count(*) from multiple tables

Posted on 2007-03-23
4
Medium Priority
?
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

604 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