Selecting random records in IBM DB2Posted by Eng.Ahmed AlSadi
For some reasons you may want to select some random records from a table to perform some processing on them, I will show how to Select random records in IBM DB2:
123 <pre>SELECT column, RAND() as IDXFROM <strong>MyTable </strong>ORDER BY IDX FETCH FIRST <strong>n</strong> ROWS ONLY
where n is the number of random records to return, MyTable is the table name.
An example to select 5 random names from names table:
1234 <pre><pre>SELECT column, RAND() as IDXFROM namesORDER BY IDX FETCH FIRST <strong>1</strong> ROWS ONLY