Re: [Q] Daves's top 10 SQL question

From: Carlos Augusto Leite Netto <cnetto_at_cps.softex.br>
Date: 1996/03/19
Message-ID: <314E7F63.19B0_at_cps.softex.br>#1/1


Chuck Hamilton wrote:
> >>But seriously, how can you code a SQL query to first order records
> >>greatest to least then pick out only a pre-selected number of them
> >>without prior knowledge of their distribution. This strikes me as
> >>a common, even simple thing to do, but I can't see how to do it, and
> >>I've written some pretty twisted queries.

select your_value
from your_table o
where 10 > (
  select count(*)
  from your_table i
  where i.value > o.value );

Very slow, but it's a nice solution.

Regards,

Carlos Netto
cnetto_at_cps.softex.br - Software Design Ltd. Received on Tue Mar 19 1996 - 00:00:00 CET

Original text of this message