Index ¦ Archives ¦ Atom ¦ RSS > Tag: query

Selecting a random row from a table in mysql

database

I have come across more than one instance when I had to select a random record from a table in a MySQL database. Here is how to do it.

The simple but slow method

SELECT * FROM mytable ORDER BY RAND() LIMIT 1;

Although simple, the above query can be very ...

© Prashanth Ellina. Built using Pelican. Theme by Giulio Fidente on github.