Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Query to find the employees in a department having maximum number of emps

547625Mar 29 2010 — edited Mar 30 2013
I need a Query to find the list of employees in a department having maximum number of employees. Though I am able to do it with the query written below, I am sure there would be a better query. Can any one help please.
select empno, ename, sal, a.deptno
from emp a, 
(select deptno from (select deptno, count(1) over (partition by (deptno)) from emp order by 2 desc) where rownum =1) b
where a.deptno = b.deptno;
Thanks in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 27 2013
Added on Mar 29 2010
9 comments
14,536 views