Jump to content

ORDER GROUP BY RAND()


The Little Guy

Recommended Posts

I cant get this to work...

 

SELECT  DISTINCT * from class_event_entered WHERE rundate='03-03-2009' ORDER BY `class` DESC, ORDER BY RAND()

 

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY RAND()

LIMIT 0, 30' at line 1

 

I would like to order the selected by class (1+ values), then within that class group order those randomly. Instead I get the above error, how can I do this?

Link to comment
https://forums.phpfreaks.com/topic/147821-order-group-by-rand/
Share on other sites

I changed my mind not solved :)

 

I would like to add to it...

 

SELECT  DISTINCT * from class_event_entered WHERE rundate='03-03-2009' ORDER BY `class` LIMIT 6, RAND()

 

I would like something like that.

 

Say class "A" has 10+ rows (10+ people apart of class "A") I only want to select 6 of those, and do that for each class in the database. How can I do this? I thought the above would work, but it doesn't.

 

So the returned values would look like so:

 

A     player1
A     player2
A     player3
A     player4
A     player5
A     player6
B     player7
B     player8
B     player9
B     player10
B     player11
B     player12
...

Link to comment
https://forums.phpfreaks.com/topic/147821-order-group-by-rand/#findComment-775892
Share on other sites

I want to grab 6 random values per class.

 

So say I have 3 classes with 10 people in each class (30 people) I want to select six random people from each class for a total of 18. That means select 6 people from class a, six people from class b and six people from class c.

 

The example above just uses 3 classes, there could more classes and there could be less classes. A class could even have less than six people in it as well.

 

How would I do that?

Link to comment
https://forums.phpfreaks.com/topic/147821-order-group-by-rand/#findComment-776596
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.