SQL for collecting random record from a tableMany times we have to collect a random record from mysql database. How to get the random record?
Here we have to use rand() function and along with it we will use limit query to restrict our result to one record. Randome funciton is used along with order by clause to generate randome records. This will work well in other database also. Here is the query. We have added on where clause also.
SELECT * FROM student where status='yes' ORDER BY RAND() limit 1To get 10 random records from the same table.
SELECT * FROM student where status='yes' ORDER BY RAND() limit 10Let us learn how to randomly update records of a table in Part II
Number of User Comments : 2