Select random records in a MySQL database

MySQL, tutorial Add comments

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

Follow me on twitter! http://twitter.com/joshhighland

Leave a Reply



WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in