2
Suppose I have such a table:
item | group
-------+--------
item a | group z
item b | group y
item c | group y
item d | group x
item e | group z
item f | group x
And that now I want to randomly select a single item to represent each group, so that, after random reordering and grouping, the result looks like this:
item | group
-------+--------
item b | group y
item d | group x
item e | group z
Or so:
item | group
-------+--------
item b | group y
item a | group z
item d | group x
Or so:
item | group
-------+--------
item f | group x
item e | group z
item c | group y
All shuffled and grouped. How can I do this?
PS1: Please note that: - time group x is associated with item d and formerly with item f; - time group y is associated with item b and formerly item c; - time group z is associated with item a and once with item, and;
PS2: If it is possible to follow the line of reasoning of this post here, it is better: Select the first row of each group in Mysql otherwise, no problem at all!
PS3: I’ve seen similar explanations using the HOVER and PARTITION command. But these commands don’t exist in Mysql. So I need help anyway.
Good dev! Super thanks for your help!!!
– Jose Henrique