Home » Mysql » Select random rows from mysql table [duplicate]

Select random rows from mysql table [duplicate]

Posted by: admin November 30, 2017 Leave a comment

Questions:

Possible Duplicate:
Selecting Random Rows in MySQL

I’m creating a simple web application using PHP and MySQL. In it, I need to randomly select a small set of rows from a table in a random order. How can I achieve such thing using MySQL?

Answers:
SELECT * FROM table ORDER BY RAND() LIMIT 10;

Edit:

Useful information about the MySQL RAND() function can be found here.

Questions:
Answers:
select * from table order by rand() limit 10

Note that order by rand() with large dataset is very slow but in your case it’s not a problem.

Questions:
Answers:

you could do that using RAND() function .

SELECT questine FROM tablename ORDER BY RAND() LIMIT 10

will select 10 questines at random under assumption the questine is stored under field questine