Sampling a Table

From TekiWiki

Jump to: navigation, search

This whole wiki has now moved to http://www.springboardsolutions.com/wiki

Go to this page Sampling a Table

(Created page with "Getting a few random rows from as Oracle Database table can be done in many different ways. This will just select the first ten rows Oracle comes across in the table: <pre> ...")
 
Line 7: Line 7:
where
where
rownum<=10
rownum<=10
-
/
 
</pre>
</pre>
They are likely to all be inserted at a similar time and therefore all similar. If you need a cross section:
They are likely to all be inserted at a similar time and therefore all similar. If you need a cross section:
 +
<pre>
 +
select *
 +
from iso_country
 +
sample (10) -- percentage of rows to display
 +
</pre>
 +
 +
The percentage of rows is not precise, there are 249 rows in the sample iso_country table, but the 10% sample count has given a range from 15 - 31 rows:
 +
 +
<pre>
 +
select count(*)
 +
from iso_country
 +
sample (10) -- percentage of rows to display
 +
</pre>
 +
 +
Additional conditions can be added to a sampling query, but they appear to be applied after the original sample has been taken, so there is no guarantee that the query will show any rows:
 +
<pre>
 +
select *
 +
from iso_country
 +
sample (10)
 +
where code like 'A%'
 +
</pre>

Latest revision as of 22:45, 19 August 2011

Personal tools