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 -> Re: Select the top 5 out of a table.

Re: Select the top 5 out of a table.

From: <tigsar_at_my-deja.com>
Date: 2000/07/14
Message-ID: <8knore$rci$1@nnrp1.deja.com>#1/1

select * from
(select name, salary from employees order by salary desc) where rownum<5

In article <B6Jb5.5505$SU5.133624_at_afrodite.telenet-ops.be>,   "Haplo" <valgaeren_at_pandora.be> wrote:
> 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
>
>

Sent via Deja.com http://www.deja.com/
Before you buy. Received on Fri Jul 14 2000 - 00:00:00 CDT

Original text of this message

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