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: Michael Dodd <doddme_at_mindspring.com>
Date: Thu, 14 Jun 2001 18:14:30 -0500
Message-ID: <tlgiit0i8dbqbivpel069e9dm9ja3g8duk@4ax.com>

On Fri, 08 Jun 2001 11:21:53 -0400, Thomas Kyte <tkyte_at_us.oracle.com> wrote:

>A copy of this was sent to "Jack" <No_at_Mail.Please>
>(if that email address didn't require changing)
>On Fri, 8 Jun 2001 12:08:27 +0100, you wrote:
>
>>Hi
>>Can you please tell me how to 'select' only (the first) 20 records of a
>>table?
>>is it ;
>> select * from tableA sample (20)
>>
>>Thanks
>>
>
>
>that'll get 20% of the rows in the table.
>
>
>select * from tablea where rownum <= 20;

You're right though about the sample- is that a random sample though? I've always wondered if it could be used for that purpose. The results look pretty random -

SQL> create table sample_20 (num number);

Table created.

SQL> declare i number := 0;
  2 begin
  3 for i in 1 .. 500 loop
  4 insert into sample_20 values(i);
  5 end loop;
  6 end;
  7 /

PL/SQL procedure successfully completed.

SQL> select * from sample_20 sample(20);

       NUM


         9
        13
        17
        18
        20
        23
        36
        39
        43
        45
        50

....
SQL> /        NUM
        14
        25
        26
        28
        34
        38
        41
        43
        45
        51
        54

...
SQL> /        NUM
        11
        33
        45
        46
        51
        57
        59
        68
        70
        83
        96

... Received on Thu Jun 14 2001 - 18:14:30 CDT

Original text of this message

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