troubleshooting Question

SQL Select with count() from another table?

Avatar of Rob Rudloff
Rob RudloffFlag for United States of America asked on
Microsoft SQL Server 2008Microsoft SQL Server
6 Comments1 Solution1534 ViewsLast Modified:
Hi.
I'd like to select * from an Department table and also include a column that is a count() of Employees in each Department.    The Department table (simplified) includes a unique Dept_ID and Description.  Each Employee in the [Emp] table has a "Dept_ID" column, indicating which department the employee is in.

So, in the end, I'd like a resultset something like:

Dept_ID   Description     Emp_Count
-------   -------------   ---------
1         Dept 1 A/P             12
2         Dept 2 Office           8
3         Dept 3 A/R             11

 Is that possible?  I was trying to use a "select" statement in a join, but am doing something wrong ...
-- Thanks
ASKER CERTIFIED SOLUTION
dsacker
Contract ERP Admin/Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros