Often in many situations during programming you might need to pull randomly selected records from a MySQL Database. For example displaying 5 randomly selected ads in your site. All that is needed is use rand() function.
SELECT ID FROM
ORDER BY RAND() LIMIT 5
Make sure you use the LIMIT clause as otherwise it would cause an overhead in the results. Note that if you use rand() function in a database with large number of records, the query would slowdown. So make sure you filter the necessary records and then apply rand() to pull out randomly selected records from the database.
Founder of Corpocrat Magazine and World’s leading expert in citizenship and residence by investment schemes assisting wealthy individuals and families. He is the founder Best Citizenships (BC), CIP Journal and World Citizenship Council (WCC) .
Other interests include Linux servers, Machine learning, Blockchain and Cryptocurrencies.