Get random results from a MySql table

By | August 20, 2011

It is possible to retrieve random results from a MySql table using the RAND() mathematical function.

In order to get the random results, the RAND() function should be used in the ORDER BY clause, like in the example below:

Retrieving random results directly from MySql is useful since you don’t need another step in your application in order to manually randomize the sql results. For example if the sql results are retrieved without being randomized you need to use a “shuffle” like function to get random results in PHP.

Leave a Reply