Wednesday, March 17, 2010

Select random records in a MySQL database

July 16, 2007 by Josh Highland  
Filed under MySQL, tutorials

mysql-logo.gif
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

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • FriendFeed
  • MySpace
  • Ping.fm
  • StumbleUpon
  • Technorati
  • Tumblr
  • Twitter
  • Yahoo! Bookmarks

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!