Return Random Record via MySQL

Return Random Record via MySQL

There are many practical and frequently used methods requiring a random record to be called. For instance, when you see “featured profiles” or random customer comments on a website, they are most likely using a function to call a random record.

In addition, this function can allow you to display data in a random order.

Here’s how it works:

SELECT field_1, field_2, field_3, field_4
FROM table_name
WHERE parameter = 1
ORDER BY RAND()
LIMIT 1

It’s that simple. Please post your feedback!

Share and Enjoy:
  • email
  • Twitter
  • LinkedIn
  • Facebook
  • Google Bookmarks
  • RSS
Your Ad Here

1 Comment to “Return Random Record via MySQL”

  1. John says:

    Thanks. I used this to display sponsored ads on my site.
    Only 2 sponsors though :)

Leave a Reply

You must be logged in to post a comment.