Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Random Picks

by tune (Curate)
on May 09, 2001 at 17:29 UTC ( [id://79071]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://79071]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 16:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found