Alright so I have this select statement that returns the department number which has the lowest number of people working as CLERKS, however it returns two departments because of the data in the database. When I add rownum=1 it gives me a completely different department number which has the most number of CLERKS and I have no idea why it does so. Help appreciated
select deptno from emp where job='CLERK' group by deptno
having count(job)=(select min(count(job)) from emp where job='CLERK'group by deptno);
I've tried using rownum in the main select statement and in the sub select statement but the same result.. I even used order by and it still produced the same result.
select deptno from emp where rownum=1 and job='CLERK' group by deptno
having count(job)=(select min(count(job)) from emp where job='CLERK'group by deptno) order by deptno;
Here is the same statement with the rownum and the order by.