affiliate marketing Interview Qns: How can I get information on the row based on group information ?

Monday, October 25, 2010

How can I get information on the row based on group information ?

Imagine we have the EMP table and want details on the employee who has the highest salary. You need to use a subquery.
select e.ENAME, e.EMPNO, e.SAL
from EMP e
where e.SAL in (
select max (e2.SAL)
from EMP e2
);
You could get similar info on employees with the highest salary in their departments as follows
select e.ENAME, e.DEPTNO, e.SAL
from EMP e
where e.SAL = (
select max (e2.SAL)
from EMP e2
where e2.DEPTNO = e.DEPTNO
);

No comments:

Post a Comment