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

H

How Can We Help?

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

About the author

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.

About Author

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.

Follow Me