How to get the data randomly from mysql

“How to get the data randomly from mysql ” the first question comes to mind when working with real time data.
Sometime we need the data randomly from the database .

Let say we have a app and which has some category.

App has some main categories and we wants a special category content to come randomly at a some place, like Riddle or Jumble Word or a question .So we required the data coming from mysql of that special category should be in RANDOM fashioned.

Here we will use the Rand function of mysql.

WHAT IS RAND function Generally :-

In mathematics or any other programming language the RANDOM function is available for generating the RANDOM results, in same way the mysql also has a RAND function

  • Random Data with simple select query:-

Select * from users random_table1

Data with RAND() function

In some case we wants the select query gave data randomly ,for that purpose we can use the RAND() function of MYSQL with ORDER BY 

Select  * from user ORDER BY RAND() random_table2

Again data with RAND() function

Select * from users ORDER BY RAND()

complete_randomdata

As you can see the above data after using the RAND() every time, the data we are getting is random.

Check it also

Leave a Reply

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