You're selecting your index column [ID] for every record and generating a
column containing a random number [ID*0+RAND()], ordering by the random
column [ORDER BY rand], and then just grabbing the first record [LIMIT 1].
the RAND() function generates random numbers.
In my version of mysql (most recent) this simpler query does the same thing:
select ID, rand() as rand from partner order by rand limit 1
which is probably easier to understand, but YMMV.
-ravi.
-----Original Message-----
From: Chris Boot [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 19, 2001 3:53 PM
To: MySQL Mailing List; Ravi Raman
Subject: Re: Selecting random rows with MySQL 3.22?
Hi,
> for mysql < 3.23 you can do something like this.
>
> select ID, ID*0+rand() as rand from partner order by rand limit 1
Thanks a million for the speedy response! It works like a charm!
I don't quite understand how it works though... Could anyone explain? I
really don't like knowing something without knowing how it works.
Best wishes,
--
.-. Chris Boot
/v\ [EMAIL PROTECTED]
// \\
/( )\ L I N U X
^^-^^ >Phear the Penguin<
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php