PL/SQL (MOSC)

MOSC Banner

correlated subquries

edited Jun 20, 2013 9:33AM in PL/SQL (MOSC) 2 commentsAnswered ✓
I am reading the OCP preperation book and it states there that subquries are bad and alternate methods should be used.

There is the subquery mentioned in the book but no alternate solution .  can someone point out an alternate solution for this?

the following query list all employees whose salary is less than the average salary of their department.

select p.last_name, p.department_id from employees p
where p.salary < ( select avg(s.salary) from employees s
where s.department_id=p.department_id)
/

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center