I need to retrieve rows from a table (i.e: ‘orders’) ordered by a column (lets say ‘user’) randomly. That is, I need all orders from the same user to remain together (one after the other) and users to be ordered randomly.
Share
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.
I’m going to assume you have a second table called ‘users’ that has all the users in it. If not, you could still do this by adding another SELECT DISTINCT subquery on orders, but that would be much messier:
You’ll want to order by the random number AND the user id so if two user ids get the same random number their orders won’t be all jumbled together.