MySQL

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

Written by Ian Carnaghan · 8 sec read >

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
Written by Ian Carnaghan
I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment. In my spare time I teach undergraduate classes in web development. Profile

Leave a Reply

avatar
  Subscribe  
Notify of