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 -> newbie question about rownum

newbie question about rownum

From: steve lancour <steve_at_lancour.tcimet.net>
Date: Tue, 25 Aug 1998 20:07:16 -0400
Message-ID: <35E351B4.E36B04B0@lancour.tcimet.net>


Hi.

        I'm trying to query an Oracle table using an order by clause, but am only interested in the first row returned by the query. For example, I have a table called EMPLOYEES with a column called NAME and want only the first record in alphabetical order by name.

        SELECT NAME FROM EMPLOYEES ORDER BY NAME; returns, as one would expect, all names in alphabetical order.

        Being interested only in the first name on the list, I tried SELECT NAME FROM EMPLOYEES WHERE ROWNUM < 2 ORDER BY NAME which, as many of you and now I know, doesn't return the first name alphabetically but rather the first name found before the ORDER BY is applied to the result of the query.

        So, how do I select a group of records in order and then return only the first record from the result set?

        Any help will be appreciated greatly. --
Steve Lancour Received on Tue Aug 25 1998 - 19:07:16 CDT

Original text of this message

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