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!

Tune SQL Query: Employee with MAX salary in each department

Orcl ApexApr 18 2018 — edited Apr 18 2018

Hi All,

How we can re write this query in efficient way, this is a replicated case of my original data with standard scott schema emp tables.

SELECT e1.*

FROM emp e1

WHERE EXISTS (

    SELECT 1

    FROM (

        SELECT deptno

             , MAX (sal) sal

        FROM emp

        GROUP BY deptno

    ) e2

    WHERE e2.deptno   = e1.deptno

          AND e2.sal      = e1.sal

)

ORDER BY deptno;

This post has been answered by Paulzip on Apr 18 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 16 2018
Added on Apr 18 2018
10 comments
2,460 views