MySQL Random Row
Last Updated on: November 27, 2022
To get a random row from your table, you can use the following trick:
SELECT * FROM myTable ORDER BY RAND() LIMIT 1
This will return a single random row from myTable.
Remember that you can also use a WHERE clause to narrow down the records before choosing a random one.
This is a more efficient way of finding a random result than it would be if you returned all the records from the table and looped through them in your code.