Here is one way:
select t.*
from t join
(select letter, rand() as rnd
from t
group by letter
) tt
on t.letter = tt.letter
order by tt.rnd;
A simpler method uses the calculation on the letter itself. Here is one way:
select t.*
from t
order by rand(ascii(t.letter));
This is canonical, so executing it twice in a row returns the same results.
source
share