SQL

Posts about using SQL

MySQL Logo

Getting A Random Row From A MySQL Table

26th December 2007 - 2 minutes read time

Getting a random row from a MySQL table requires the use of the RAND() function in the ORDER BY clause of the SELECT statement. This will generate a new random number for each row and order them by that new number. In order to get a single row this is combined with the LIMIT clause to limit the result to a single row.

SELECT * FROM theTable ORDER BY RAND() LIMIT 1;

Read the full article