Possible Duplicate:
Simple Random Samples from a (My)Sql database
Hi!
Let say that I have a table of users. I want a query that shuffle the result and only show 5 users. How do I do that in MySQL query without using any php?
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.
You can use
rand(), but the performance is terribleI would suggest, store list of all user id into an serialize array and cache into a disk-file. (periodically update)
So, you can un-serialize it back using PHP, and use PHP
array_randto pick 5 random users.To fetch the full information, you can do