Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Select the top 5 out of a table.

Select the top 5 out of a table.

From: Haplo <valgaeren_at_pandora.be>
Date: 2000/07/14
Message-ID: <B6Jb5.5505$SU5.133624@afrodite.telenet-ops.be>#1/1

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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US