Ordering is not a good idea, especially for large tables.
We have an ability to use built-in Db2 for LUW feature of subselect
- tablesample-clause.
BERNOULLI
BERNOULLI sampling considers each row individually. It includes each row in the sample with probability P/100 (where P is the value of
numeric-expression1), and excludes each row with probability 1 -
P/100, independently of the other rows. So if the numeric-expression1
evaluated to the value 10, representing a ten percent sample, each row
would be included with probability 0.1, and excluded with probability
0.9.
SYSTEM
SYSTEM sampling permits the database manager to determine the most efficient manner in which to perform the sampling. In most cases,
SYSTEM sampling applied to a table-name means that each page of
table-name is included in the sample with probability P/100, and
excluded with probability 1 - P/100. All rows on each page that is
included qualify for the sample.
Example:
SELECT *
FROM MYTABLE TABLESAMPLE SYSTEM (0.1)
FETCH FIRST 10 ROWS ONLY;
This feature doesn't exist in DB2 for IBM i/iSeries/OS400. Use the order by rand() fetch first 10 rows
clause for this platform instead.