Mysql Query – Set 4

Given an Employee table with following structure

EmpId EmpName Department ManagerId

Part 1: Write a sql to retrieve all Manager’s Name with 5 or more subordinates.

Note : ManagerId is also an Employee Id.

select EmpName from Employee where EmpId IN 
(select ManagerId from Employee 
 Group by ManagerId 
 Having count(EmpName)>=5);

Part 2 : Write a sql to retrieve ManagerId who have 5 or more subordinates in one column and comma separated subordinates names in other column .

select ManagerId,group_concat(EmpName) 
From Employee
Group by ManagerId
Having count(EmpName)>=5

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Post Navigation