stackuser stackuser - 2 months ago 12
SQL Question

How to list the employees who are senior to most recently hired employee working under a particular manager in the below schema?

I have a schema of emp table defined as emp ( empno ,ename ,job ,mgr ,hiredate) and I have to evaluate the query for the problem statement :

List the employees who are senior to most recently hired employee working under king.

I wrote the query as :

select hiredate from emp where hiredate < ANY
( select e.hiredate from emp e where e.mgr= (select e.empno from emp e
where e.ename='KING') order by hiredate desc )


This query is giving syntax error ,please help me out .

Answer

Use max function instead-

select hiredate 
from emp 
where hiredate < ( select max(hiredate) 
                   from emp 
                   where mgr= (select e.empno 
                               from emp e 
                                where e.ename='KING')); 
Comments