Puzzle of the Week #6 -Top paid employees

Puzzle of the Week #6

Find all employees who is paid one of top 4 salaries in the entire company without using sub-queries and in-line views/WITH clause.

Expected Result:

ENAME             SAL
---------- ----------
KING             5000
FORD             3000
SCOTT            3000
JONES            2975
BLAKE            2850

To submit your answer (one or more!) please start following this blog and add a comment to this post.

A correct answer (and workarounds!) will be published here in a week.

If you like this post, you may want to join my new Oracle group on Facebook: https://www.facebook.com/groups/sqlpatterns/

For more tricks and cool techniques check my book “Oracle SQL Tricks and Workarounds” for instructions.

Advertisements

7 thoughts on “Puzzle of the Week #6 -Top paid employees

  1. Ashwini Kumar April 6, 2016 / 10:11 pm

    SELECT *
    FROM employee
    ORDER BY salary DESC
    FETCH NEXT 4 ROWS ONLY;

  2. Ashwini Kumar April 7, 2016 / 4:34 am

    SELECT ename,sal
    FROM emp
    ORDER BY sal DESC
    FETCH first 30 percent ROWS ONLY;

    • Zahar Hilkevich April 7, 2016 / 8:48 am

      30% do not guarantee top 4 salaries. What if we get more employees hired?

  3. viral barot April 10, 2016 / 11:07 pm

    Select e.ename , s.salary where e.id = s.eid order by s.salary desc limit 4 employees as e , salary as s

  4. viral barot April 11, 2016 / 12:05 am

    Select e.ename , s.salary from employees as e , salary as s where e.id = s.eid order by s.salary desc limit 4

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s