HOW TO SELECT RANDOM RECORDS FROM MYSQL TABLE?

Arun Singh

Total Post:68

Points:476
Posted by  Arun Singh
MYSQL 
 2260  View(s)
Ratings:
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.
  1. Pravesh Singh

    Post:412

    Points:2888
    Re: How to select random records from MySQL table?

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!