Solution
Selecting random rows from a MySQL database table can be useful in order to display advertisements or any other kind of specific information.
To extract random rows use a SELECT statement ordered by the RAND() clause.
Example
SELECT * FROM users ORDER BY RAND() LIMIT 1;
The example query will extract all columns of a single row of table users. To select more rows increase the LIMIT of the query.
Disadvantages
The presented method for extracting random rows might be slow for tables consist of more than a million rows.
Reference Manual
MySQL Select Syntax
|