Snippet Name: Fast random row picker one Description: This method of selecting a random row is fairly fast. Comment: (none) Language: MYSQL Highlight Mode: MYSQL Last Modified: February 28th, 2009
Description: This method of selecting a random row is fairly fast.
LOCK TABLES foo READ; SELECT FLOOR(RAND() * COUNT(*)) AS rand_row FROM foo; SELECT * FROM foo LIMIT $rand_row, 1; UNLOCK TABLES;