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

Home -> Community -> Usenet -> c.d.o.misc -> Re: Getting the first row from a select

Re: Getting the first row from a select

From: <gbray1_at_my-dejanews.com>
Date: 1998/10/07
Message-ID: <6vgjp0$nkq$1@nnrp1.dejanews.com>#1/1

The rownum = 1 will often work correctly. Of course, if you use an ORDER BY clause then you complicate things. If you use the order by clause then the order by happens AFTER the rownum = 1 criteria is met which then often gives the wrong answer. I say often because if your where clause causes Oracle to use the same index that the order by uses then you can get away with the order by clause because Oracle is reading in the order of the index.

Geoffrey Bray
Tandy Corp.

In article <#v$bRBg89GA.188_at_nih2naab.prod2.compuserve.com>,   "David Ferguson" <DavidFerguson_at_csi.com> wrote:
> >Maybe I'm missing something obvious....
> >
> >I'm trying to write a VB program that will get the first record from a
 query
> >something like:
> >
> >select * from COMPANY where COMPANY_NAME >= 'whatever was entered';
> >
>
> Using the dbOpenForwardOnly type of recordset may eliminate the cost of
> doing the simple query and only using the first retrieved column.
>
> Under certain conditions you can get the first row by adding the clause
> ROWNUM=1 to the query.
>
> Cheers...David
>
>

-----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own Received on Wed Oct 07 1998 - 00:00:00 CDT

Original text of this message

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