SQL for collecting random record from a table

Many 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. Random function is used along with order by clause to generate random 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 1
To get 10 random records from the same table.
SELECT * FROM student where status='yes' ORDER BY RAND() limit 10
Let us learn how to randomly update records of a table in Part II


* indicates required
Subscribe to plus2net


    Dev Pandey


    select * from tableName order by rand() limit 0,1;


    What is the use of Random records ?

    Post your comments , suggestion , error , requirements etc here .

    SQL Video Tutorials

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2022 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer