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: How would you retrieve the first five records

Re: How would you retrieve the first five records

From: Alexandre Leite <aleite_at_sysdesign.com.br>
Date: Mon, 29 Mar 1999 10:20:34 -0300
Message-ID: <7dnuij$qf6$1@srv4-poa.nutecnet.com.br>


Comments in line.

taratatata_at_my-dejanews.com escreveu na mensagem <7dm4t5$k4v$1_at_nnrp1.dejanews.com>...
>
>
>I am new to sql, I want to retrieve the first five records that
>satisfy a condition and get the last record number checked by
>sql.
>
>Let's say I have 10000 records, some 5000 records includes the string
>"dollar", but I need to retrive only the first five records that include
>this string, and I want to get the record number of the first record
>that comes immediatly after the fifth retrieved record.
>

I think this sql stament can help you:

select a.column1, a.column2, a.my_string, ..., c.max from table a, (select max(rowid) max from table where my_string like '%dollar%') c
where a.my_string like '%dollar%'

    and 5 > (select count(*)

                   from table b
                   where b.my_string like '%dollar%'
                       and b.rowid < a.rowid)

This sql is not the best aproach, for high performance you could use pl/sql cursors.

>I check the syntax of "select" but it does not have a way to get my
results,
>any help would be very much appreciated.

>
>Thanks everybody.
>Susan
>Toronto, Canada
>

>-----------== Posted via Deja News, The Discussion Network ==----------
>http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own

Alexandre Leite
leite_alexandre_at_hotmail.com Received on Mon Mar 29 1999 - 07:20:34 CST

Original text of this message

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