Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: First 20 records only

Re: First 20 records only

From: Niall Litchfield <niall.litchfield_at_dial.pipex.com>
Date: Sat, 9 Jun 2001 10:46:01 +0100
Message-ID: <3b21ef8f$0$12246$cc9e4d1f@news.dial.pipex.com>

"Jack" <No_at_Mail.Please> wrote in message news:0n2U6.69731$662.285365_at_news1-hme0...
> Hi
> Can you please tell me how to 'select' only (the first) 20 records of a
> table?
> is it ;
> select * from tableA sample (20)

various people have given you the where rownum < 21 answer. This is absolutely fine if you only want 20 records and do not care which they are. If you do care which they are (the top 20 sales for example) you'll need to look on deja for the answers in this group to the equivalent of TOP. 8i and above the syntax is (from memory)

select * from (select ... from table order by key_column desc) where rownum < 21;

I believe that Jonathan Lewis has pointed out that order by in an inline view has got back-ported to some patch releases of 7.3 as well.

--

Niall Litchfield
Oracle DBA
Audit Commission UK
Received on Sat Jun 09 2001 - 04:46:01 CDT

Original text of this message

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