Withdata Software

How to select N random records from a DB2 table

If you want to select N random records from a DB2 table, you need to change the clause as follows:

select * from tableName order by rand() fetch first N rows only

For example, to select 5 random customers in the customers table, you use the following query:

select * from customers order by rand() fetch first 5 rows only

Some DB2 tools you can try: https://www.withdata.com/db2/