Select Page

How to get random rows when querying a database table using MySQL

For example, if you have a table with 100 rows in it and you need to get 3 random rows then this could come in handy. 

SELECT * FROM ads ORDER BY RAND() LIMIT 3

We’ve used the RAND() function to return random table rows

Last Updated On March 23, 2018

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.