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

Re: newbie question about rownum

From: <nasof_at_hotmail.com>
Date: Wed, 26 Aug 1998 12:56:33 GMT
Message-ID: <6s10m1$217$1@nnrp1.dejanews.com>


I believe this will work:

Create a view of your sql statement, you cant use Order By in a view, but you can GROUP BY <name> and it will do an order by.

Then you select * from view_name where rownum<10;

-Frank

In article <35E351B4.E36B04B0_at_lancour.tcimet.net>,   steve lancour <steve_at_lancour.tcimet.net> wrote:
> 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
>

-----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum Received on Wed Aug 26 1998 - 07:56:33 CDT

Original text of this message

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