Softwarex3
Softwarex3

Reputation: 33

Select top 10 salary from employees table

I wrote this sql query:

select first_name, salary 
from employees 
where salary in( select distinct top(10) salary from employees order by salary  disc );

When I ran it, I got this error:

SQL Error: ORA-00907: missing right parenthesis 00907. 00000 - "missing right parenthesis"

What could have caused the error?

Upvotes: 0

Views: 65860

Answers (6)

Sneha R
Sneha R

Reputation: 66

This will work

select emp_id, salary from orders
order by salary desc limit 10;

Upvotes: 0

Rahul
Rahul

Reputation: 17

The below Query works in Oracle.

select * from (select * from emp order by sal desc) where rownum<=10;

Upvotes: 0

Patrick Hofman
Patrick Hofman

Reputation: 156978

I think the problem lies in the use of top which is SQL Server and not Oracle.

Use rank instead to get the salary in the decent order and get the first 10 of them:

select v.first_name, v.salary 
from ( select first_name, salary, rank() over (order by salary desc) r from employees) v
where v.r <= 10

Upvotes: 2

TMNT2014
TMNT2014

Reputation: 2130

Try -

SELECT first_name, salary 
(  select first_name, salary 
   from employees 
   order by salary Desc)
where rownum <= 10

Upvotes: 1

Kirill Leontev
Kirill Leontev

Reputation: 10941

Top-N query is typically performed this way in Oracle:

select * from (
select first_name, salary 
from employees order by salary desc
) where rownum <= 10

This one gets you top 10 salaries.

Upvotes: 6

Tech.Kabir
Tech.Kabir

Reputation: 11

Try this === SELECT first_name, salary FROM employees WHERE salary IN (SELECT salary FROM employees GROUP BY salary ORDER BY salary DESC LIMIT 10);

Upvotes: -3

Related Questions