I have an emp
table with the records below:
INSERT into emp(EmpId,Emp name, Manager)
Values(1,A,M1)
values(2,B,M1)
values(3,C,M2)
values(4,D,M3)
If you want the row from the emp table, use this:
select * from emp
where empid in (select manager from
(select manager, count(*)
from emp
group by 1
having count(*) = (select max(count) from (select manager, count(*) as count from emp group by 1) x)
) y );
This will also return multiple rows in case there is a tie for the most number of employees.