Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm 
(http://www.ezmlm.org)
   From: "W. Enserink" <[EMAIL PROTECTED]>
   Date: Fri, 20 Sep 2002 09:08:53 +0200

   anyone knows a good method to retrieve 1 random selevted record out of
   thouseands?

   right now I'm using

   select ID from table ORDER BY rand() LIMIT 1

   however, this seems like a very slow method, like mysql first organizes a
   few thousand records in a random 1 and only returns 1....

   Any help would be great!

If you have a unique and continous index, then perhaps something like
may be useful:

select truncate(rand()*count(*),0) from TABLE;

it was only 3 times faster than your current however.

---------------------------------------------------------------------
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

Reply via email to