• How often do you need to do this?
  • You just need a collection of the record id's (pk's) from the table, like a long-ass list (I believe the IT acronym for that would be "lal"). Can you schedule the process to create your lal, perhaps cache it for a bit?
  • generate your random number from 1 to (length of your collection). Then use the listGetAt() function to pluck the pk of your winning record from the lal. Select the complete record at this time if you need more data.
  • add the winning record pk to another list (or perhaps the record to a winners table).
  • repeat the random part, and compare the result to your winners list to prevent dup's
  • stop at 20
Al

On 3/17/2011 12:48 PM, Jason Allen wrote:
Hi Guys,

I have a collection built that could potentially have 10,000 or more
records.

I need to query this catalog and grab 20 random records from it.

What would be the best way to do this? Right now all I can think to do
is to perform a cfsearch on the catalog with criteria="*" (wild card),
then do a sql query on that recordset, using some kind of
randomization function and putting a limit on how many rows are
fetched (maxrows=20").

Is there a more direct way to do this when I perform the original
cfsearch on the collection? That way the initial query doesn't need to
grab every single record?

This function will be executed fairly often so I want to reduce the
overhead it creates.

Thanks!

--
official tag/function reference: http://openbd.org/manual/
mailing list - http://groups.google.com/group/openbd?hl=en

Reply via email to