Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.tools -> Re: First 20 records only
"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 UKReceived on Sat Jun 09 2001 - 04:46:01 CDT