Here's the weird part... From the looks of it, each row will have a different value in "randy" but, it doesn't seem to want to sort by that field unless you put in the whole formula mess. I do not know why this is.
I just noticed I am running 3.22 (time to upgrade I guess). When I run the query you mentioned, I get different results:
+-----------+-------+--------+
| name | votes | RND |
+-----------+-------+--------+
| Sue | 0 | 0.0451 |
| Calvin | 0 | 0.1138 |
| Rudolph | 0 | 0.4336 |
| Tyrone | 54 | 0.8268 |
| Shawakita | 0 | 0.8332 |
| Dave | 200 | 0.6854 |
| Zamboni | 0 | 0.9276 |
| Fish | 0 | 0.5818 |
| Goat | 0 | 0.1260 |
+-----------+-------+--------+
amd for the next run:
+-----------+-------+--------+
| name | votes | RND |
+-----------+-------+--------+
| Sue | 0 | 0.8848 |
| Calvin | 0 | 0.0459 |
| Rudolph | 0 | 0.5753 |
| Tyrone | 54 | 0.7388 |
| Shawakita | 0 | 0.9679 |
| Dave | 200 | 0.6232 |
| Zamboni | 0 | 0.2122 |
| Fish | 0 | 0.1916 |
| Goat | 0 | 0.3214 |
+-----------+-------+--------+
The numbers are all different, and the query is select *, rand() as RND from baby_names order by RND;
The names are all in the same order each time. When I use the formula trick I get
+-----------+-------+--------+
| name | votes | RND |
+-----------+-------+--------+
| Fish | 0 | 0.8791 |
| Tyrone | 54 | 0.6575 |
| Zamboni | 0 | 0.6501 |
| Shawakita | 0 | 0.2782 |
| Goat | 0 | 0.4406 |
| Sue | 0 | 0.3682 |
| Calvin | 0 | 0.5194 |
| Dave | 200 | 0.4922 |
| Rudolph | 0 | 0.9028 |
+-----------+-------+--------+
using the query
select , (votes0 + rand()) as RND from baby_names order by RND;
Again, the RND column doesn't appear to be in any particular order, but the results are seemingly randomized.
I'm off to upgrade mysql now I think... Anything I should be wary of in the upgrade?
Thanks,
Dave