Home > DeveloperSection > Forums > How to select random records from MySQL table?
Arun Singh

Total Post:68

Posted on    March-10-2012 2:35 AM


 1 Reply(s)
 2180  View(s)
Rate this:
Hello Everyone,
I'm facing a problem since last night, actually I want to select records from MySQL table randomly. So please tell me whether any option in MySQL database to perform this action.

Please reply as soon as possible.

Pravesh Singh

Total Post:412

Posted on    March-12-2012 1:20 AM

Hi Arun Singh,
To select record from MySQLdatabase randomly, you can use ORDER BY RAND() function. This function returns table values randomly. You can use this as follows.

Query: SELECT * FROM `table` ORDER BY RAND() ;

You can also use this query to perform this action.

Query:  SELECT * FROM `table` ORDER BY RAND() LIMIT 2;
 where limit is used for random id limit.

I hope this solution might be helpful for you.

Modified On Mar-12-2012 01:36:42 AM

Don't want to miss updates? Please click the below button!

Follow MindStick