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 -> How Can I Select a Specific Number of Rows Using a Sorting Criterion?

How Can I Select a Specific Number of Rows Using a Sorting Criterion?

From: Helge <hmoulding_at_gmail.com>
Date: 21 Jun 2006 10:12:48 -0700
Message-ID: <1150909968.563543.206030@m73g2000cwd.googlegroups.com>


I'd like to do something like this:

insert into temp_table_1 select id_number, criterion from source_view order by criterion ;
insert into temp_table_2 select id_number, criterion from temp_table_2 where rownum <= 5000 ;

Of course, the order by clause isn't allowed in a subquery.

Instead I've come up with a brute force method, which is to mark all rows that I want to include, count the marked rows, and if they aren't enough increase the selection criterion by one step and mark the rows again. Repeat until the count is large enough. It's not very elegant, but it's the only method I could think of.

Does anyone else have a better way to do this? Received on Wed Jun 21 2006 - 12:12:48 CDT

Original text of this message

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