Re: Selecting only the first row from a query

From: Suman Guha <xxx_at_xxx.xxxx>
Date: 1995/12/01
Message-ID: <DIwvnz.Gsy_at_txnews.amd.com>#1/1


"Brian M. Biggs" <bbiggs_at_cincom.com> wrote:
>joel_nylund_at_mail.amsinc.com (Joel Nylund) wrote:
>>
>>
>>I need to write a sql statement to only return the first row that meets >the criteria. For example I have a table called people wit=
 h names and >phone numbers. There may be several "Joel Nylund's" in the table, I only >want the first one I find.

>>
>>in DB2, I can do a select first
>>
>>I am looking for something that will work in oracle and sybase.
>>
>>thanks in advance
>>Joel
>
>Try the following:
>
>SELECT phone_number
>FROM people
>WHERE name = 'Joel Nylund' AND
> rownum = 1;
>
>This will return the first row in the result set. Note that if you stick
>an ORDER BY clause on the query, the row number (rownum) is determined
>BEFORE the sort takes place. This would only have an effect if you did
>something like 'WHERE rownum <= 50' to return the first 50 rows of a
>query result.
>
>--
>Brian M. Biggs mailto:bbiggs_at_cincom.com
>Cincom Systems, Inc. voice: (513) 677-7661
>http://www.cincom.com/
>
>

I don't have any Sybase experience. But do we have rownum in Sybase ?

Thanks,
Suman. Received on Fri Dec 01 1995 - 00:00:00 CET

Original text of this message