Random rows in MySQL
by RedCoupe on Sep.08, 2010, under Web design / development
A competition has been running on a website and all the entries were stored in a MySQL table.
Had to get a random record to pick a winner once the closing date had passed.
Here’s the SQL I used:
SELECT * FROM t_tablename ORDER BY RAND() LIMIT 1
If I had wanted to pick out 5 random winners, then change the LIMIT value to LIMIT 5.