15,999,861 members
1.00/5 (1 vote)
See more:
Here i am using three tables like...

Employee , Employee Name , Department

ID Ecode Dept ID Ename ID deptName
1 10 1 1 raja 1 Admin
2 20 2 2 siva 2 prodn
3 30 3 3 kamal 3 Accounts
4 40 5 4 ramu

how can i count total number of employees in each department and department name

My Query....
SQL
```select
Employee.ID,Employee.Dept,
Department.ID,Department.DepartmentName,
EmployeeName.ID,EmployeeName.Ename

from
(Employee inner join Department on Employee.Dept=Department.ID)
inner join EmployeeName on Employee.ID=EmployeeName.ID select COUNT(id) from Employee;```

But it counted total number of emp.ID....
Posted
Updated 29-Jan-14 19:07pm
v2

## Solution 1

how can i count total number of employees in each department and department name

You can use the group by clause in your query.

for example the following query will give you the total number of employees and depart name

Select COUNT(Employee.id) as TotalEmployees ,Department.ID,Department.DepartmentName from Employee inner join Department on Employee.Dept=Department.ID GROUP BY Department.ID,Department.DepartmentName

Karthik_Mahalingam 30-Jan-14 2:03am
4

## Solution 2

Hi,

For Total No Of Employees

Select Count(ID) as [Total No Of Employees] from Employee

For Total No Of Employees for Each Department

Select Count(e.ID) as [Total No Of Employees for Each Department], d.ID, d.deptName from Employee e
Inner Join Department d on d.ID = e.Dept
Group By d.ID, d.deptName