http://qs321.pair.com?node_id=318517


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