Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> newbie question about rownum
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
![]() |
![]() |