| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.server -> Select the top 5 out of a table.
For example:
table employees with two columns name, salary
When asked for the 5 people with the highest salary, I would do a select like this :
SELECT name, salary
FROM employees emp1
WHERE 5 > (SELECT COUNT(salary )
FROM employees emp2
WHERE emp2.salary > emp1.salary)
ORDER BY salary;
But I've heard that there is a better (more performant) solution than this. Does anybody know how?
Thanks,
Wim Valgaeren Received on Fri Jul 14 2000 - 00:00:00 CDT
![]() |
![]() |