Hello Guys ..I have a question :

I have two tables employees and department .. employees table have forign key to depatment dept_id (pk) ..
i want to know which deapartment has maximum number of employees ... i have done little , but it give number of
employees in each depaertment ...

SELECT COUNT(emp_id)
FORM 
    employees
GROUP BY 
    dept_id
Member Avatar
SELECT COUNT(emp_id) AS cnt, dept_id
FROM 
    employees
GROUP BY 
    dept_id
ORDER BY cnt DESC
LIMIT 1

Use a join if you want the name of the dept returned

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.