Randomly Select Row From MySql Table

To randomly select a row from a MySql table, use the following:

SELECT * FROM tableName ORDER BY RAND() LIMIT 1

The RAND() function will randomly sort the selected data. The LIMIT X will select the first X data rows. In this example, X equals 1, so it is the equivalent to one row randomly selected. If you want to randomly select more than one row, set X to the number of random rows you want to retrieve.

Share and Enjoy:
  • Digg
  • DotNetKicks
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Live
  • MySpace
  • Netvibes
  • Reddit
  • StumbleUpon
You can leave a response, or trackback from your own site.

Leave a Reply