Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Is there a good way of retrieving entries randomly from a database (MySQL perhaps)?

by epoptai (Curate)
on Jan 03, 2004 at 15:55 UTC ( #318517=note: print w/replies, xml ) Need Help??


in reply to Is there a good way of retrieving entries randomly from a database (MySQL perhaps)?

You can select any number of random rows by limiting the results of your query:
SELECT question, answer FROM table ORDER BY RAND() LIMIT 1
It'll be much faster and more efficient than pushing all the results into an array and dumping them into a temporary table. That seems like too much work for the task you described, unless there's a good reason for the temp table.

--
perl -MO=Deparse -e"u j t S n a t o e h r , e p l r a h k c r e"

  • Comment on Re: Is there a good way of retrieving entries randomly from a database (MySQL perhaps)?
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://318517]
help
Chatterbox?
[planetscape]: sleep well, Corion
[stonecolddevin]: erix seems pretty good, i listened to "So Many Roads" and it was nice. Not everyone's cup of tea but this guy can absolutely shred, he and the guy from Mastodon are definitely up there: https://www. youtube.com/watch? v=VzhMkSN9dQc
[erix]: ha, good stuff - loud and fast...
[stonecolddevin]: here's some Mastodon for when you have 13 minutes to have your mind blown: https://www. youtube.com/watch? v=4pvfQtUhtNE

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2017-06-22 21:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (531 votes). Check out past polls.