>From: Brent Baisley [mailto:brenttech@stripped]
>Sent: Saturday, December 06, 2008 11:35 AM
>Cc: mos; mysql@stripped
>Subject: Re: Randomize by Score and DESC
>That's because RAND() is a decimal (0.37689672). Try score*RAND().
[JS] That in itself shouldn't matter. A random number is a random number,
regardless of the scale. ORDER BY RAND() is equivalent to ORDER BY
As for ordering by score*RAND(), if score comes up 12 and RAND() comes up
.1, you will have a product equal to 1.2; if score comes up as 10 and RAND()
comes up .2, then you'll have a product equal to 2.0. That is not going to
give you what you want.
I'm pretty sure what you need to do is come up with a random sample first,
and then order the result.
SELECT score FROM (SELECT score FROM table WHERE RAND() < .1) ORDER BY score
That should give you a random sample of approximately 10% of your original
table, in descending order by score.
The Infoshop by Global Information Incorporated
195 Farmington Ave.
Farmington, CT 06032
860.674.8796 / FAX: 860.674.8341
>On Nov 30, 2008, at 2:03 AM, sangprabv wrote:
>> Thans for the reply, I have tried it but I don't see the RAND() to be
>> work. This list is always the same. TIA
>> -----Original Message-----
>> From: mos <mos99@stripped>
>> To: sangprabv <sangprabv@stripped>, mysql@stripped
>> Subject: Re: Randomize by Score and DESC
>> Date: Sat, 29 Nov 2008 13:05:09 -0600
>> Mailer: QUALCOMM Windows Eudora Version 126.96.36.199
>> At 09:15 AM 11/29/2008, sangprabv wrote:
>>> I have a query like this "SELECT * FROM table ORDER BY score DESC,
>>> RAND()" The aim is to randomize the result by score with descending
>>> order. But it doesn't work. What missed here? TIA.
>> That is because you are ordering by Score then Rand. If Score
>> is an
>> integer, try
>>> SELECT * FROM table ORDER BY score+RAND() DESC
>> This will randomize the higher scores first, followed by the lower
>> scores etc..
>> MySQL General Mailing List
>> For list archives: http://lists.mysql.com/mysql
>> To unsubscribe:
>MySQL General Mailing List
>For list archives: http://lists.mysql.com/mysql
>To unsubscribe: http://lists.mysql.com/mysql?unsub=1