Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Question about Having subquery

Author  Topic 

Tenmakk
Starting Member

1 Post

Posted - 2012-04-05 : 08:31:37
I have this code:

 SELECT department.department_name,  count(employee.department_id) as number_of_employee
FROM employee, department
where department.department_id = employee.department_id
group by department.department_name, employee.department_id
having count(*) = (select max(count(employee.department_id)) from employee, department group by department.department_name, employee.department_id)


My program works as expected, but I'm unclear about what the "having" part does:


having count(*) = (select max(count(employee.department_id)) from employee, department group by department.department_name, employee.department_id)


Can someone help me out?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-05 : 10:36:40
that will ensure you will details of department with highest employee count

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -