in reply to Random Picks

I have found an interesting solution (just type "mysql random rows" into google). It is fantastic, and fast!

  1. Add a FLOAT column to the table:
    ALTER TABLE random_selectable ADD random FLOAT;
  2. Fill this column with random numbers:
    UPDATE random_selectable SET random = RAND();
  3. Get 1000 values:
    SELECT * FROM random_selectable ORDER BY random LIMIT 1000;

--
tune

Replies are listed 'Best First'.
Re: Re: Random Picks
by mr.nick (Chaplain) on May 09, 2001 at 17:37 UTC
    Whoa! Way too complex there! Try this
    select * from table order by rand() limit 1000;
    There's no need to modify the table just to select a row at random from it.