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: SQL Question.

Re: SQL Question.

From: Jerry Gitomer <jgitomer_at_hbsrx.com>
Date: Fri, 11 Jun 1999 09:04:36 -0400
Message-ID: <7jr58r$51d$2@autumn.news.rcn.net>


Hi Terry,

    I just tried this on Oracle 7.3.2 on SCO and it won't execute. With both a WHERE rownum<11 and an ORDER BY clause I got a message about my query not being properly ended. If I comment either of these clauses out the query runs.

    What version of Oracle (and OS) are you running on?

regards

Jerry Gitomer


Terry Sullivan wrote in message <7jqm0o$iak$1_at_lure.pipex.net>...
>>I wonder if there is a way to select, for instance, the last 10 rows of
>>a table. I know that i can select the first 10 rows by:
>>
>>SELECT *
>>FROM CUSTOMERS
>>WHERE ROWNUM<10;
>>
>>Thanks in advance.
>>Roberto Pérez Lita.
>
>
>If you use the following code:
>
>SELECT *
>FROM CUSTOMERS
>ORDER BY CUST_ID
>WHERE ROWNUM<11;
>
>and CUST_ID is a Primary Key then the order in which the rows are returned
>will give you the first 10 rows.
>
>Similarly if you use :
>
>SELECT *
>FROM CUSTOMERS
>ORDER BY CUST_ID DESC
>WHERE ROWNUM<11;
>
>then this would give you the last 10 rows.
>
>This is because Oracle assigns ROWNUM in the order in which the rows are
>retrieved. If it uses an index to retrieve the rows (and it should if you
>are using a primary key) then the result should be as expected above. I
>have tried it and it seems to work.
>
>Terry
>
>
Received on Fri Jun 11 1999 - 08:04:36 CDT

Original text of this message

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