Get random entries in MySQL and MariaDB

If you want to get a random value (or more than one) from a MariaDB or MySQL database, you can accomplish this quite easy.

All you have to do is to order by RAND() and limit the amount of values to return.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.