If you want to select N random records from a SQLite table, you need to change the clause as follows: select * from tableName order by RANDOM() limit N For example, to select 5 random customers in the customers table, you use the following query: select * from customers order by RANDOM() limit ... Read more
Tag Archives: random records
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() ... Read more
How to select N random records from a PostgreSQL table
If you want to select N random records from a PostgreSQL table, you need to change the clause as follows: select * from tableName order by random() limit N For example, to select 5 random customers in the customers table, you use the following query: select * from customers order by random() ... Read more
How to select N random records from a SQL Server table
If you want to select N random records from a SQL Server table, you need to change the clause as follows: select top N * from tableName order by newid() For example, to select 5 random customers in the customers table, you use the following query: select top 5 * from customers order by ... Read more
How to select N random records from a MySQL table
If you want to select N random records from a MySQL table, you need to change the clause as follows: select * from tableName order by rand() limit N For example, to select 5 random customers in the customers table, you use the following query: select * from customers order by rand() limit 5 Some ... Read more
How to select N random records from an Oracle table
If you want to select N random records from an Oracle table, you need to change the clause as follows: select * from ( select* from tableName order by dbms_random.value ) where rownum <= N; For example, to select 5 random customers in the customers table, you use the following ... Read more