Aryan PrajapatKnowledge Contributor
How to select random rows from a table?
How to select random rows from a table?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Questions | Answers | Discussions | Knowledge sharing | Communities & more.
Using the RAND() function in combination with ORDER BY and LIMIT. In some SQL flavors, such as PostgreSQL, it’s called RANDOM(). For example, the following code will return five random rows from a table in MySQL:
SELECT * FROM table_name
ORDER BY RAND()
LIMIT 5;