Select random records in a MySQL database

by Josh Highland on July 16, 2007

mysql logo Select random records in a MySQL database
Say you want to select some random records in a MySQL database. Here is a fast way to do it:

SELECT *
FROM tableName
WHERE conditions
ORDER BY Rand()

Using the Rand() function will randomly select the rows. You can limit the number of rows returned by using the LIMIT command

  • digg Select random records in a MySQL database
  • facebook Select random records in a MySQL database
  • stumbleupon Select random records in a MySQL database
  • twitter Select random records in a MySQL database
  • delicious Select random records in a MySQL database
  • reddit Select random records in a MySQL database
  • friendfeed Select random records in a MySQL database
  • posterous Select random records in a MySQL database
  • tumblr Select random records in a MySQL database

Leave a Comment

Previous post:

Next post: