6
May
2009
SQL: SELECT random number of rows
Here’s a quick way of requesting a random number of rows from a MySQL database:
SELECT * FROM <tablename> order by rand() limit <n>;
tablename: is the name of the table you wish to access
n: is thenumber of rows you wish to return
Be careful though, don’t use this logic on a database with a large record, the performance will be unpleasant.