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)
In SQL Server...
SELECT TOP 1 Manager
FROM ( SELECT Manager,
COUNT(Manager) as "ManagerCount"
FROM emp
GROUP BY Manager
ORDER BY "ManagerCount" DESC )
Oracle is a bit different...
SELECT Manager
FROM ( SELECT Manager,
COUNT(Manager) as "ManagerCount"
FROM emp
GROUP BY Manager
ORDER BY "ManagerCount" DESC )
WHERE ROWNUM <= 1