tags:

views:

30

answers:

2
select  salary from employees order by salary desc
MINUS
select  salary from employees where rownum<10 order by salary desc;

I am unable to use order by with MINUS ,it says sql command not properly ended. Please suggest!

+2  A: 

Not sure if this is your issue but you don't need the first "order by salary desc" as ordering should be applied to the whole result set.

Martin Smith
+2  A: 

Given what the business question seems to be (show the salaries of employees where the salary is not in the top ten of salaries) I would think analytics would be a choice worth considering:

select salary 
  from (select salary,
               rank() over (order by salary) as salary_rank
          from employees
       )
 where salary_rank > 10
 order by salary;

Using analytics would also only scan EMPLOYEES once, whereas the original query would scan it twice.

Adam Musch