Is there an easy way to pick a random record from a database. I have a
unique ID for each record, but it is not strictly sequential because of
record deletions.

Here is my thought:

Run a query and get the MAX and MIN IDs.
Do a loop using them as the beginning and ending range and generate a random
number between them.
See if that number exists in the ID field of the db.
If yes, get the record, if not, try again.
Do this until you get a hit.
Alternatively I guess you could gen a random number and take the next higher
number unless it is the highest number.

That seems way to intensive and I know there must be a cleaner way. The
programmers must know a good way to do this.

Any thoughts or SQL code would be greatly appreciated.

Thanks.

Gary McNeel, Jr.
Project Manager - DAC-Net, Research & Graduate Studies
Rice University - Houston
[W] 713-348-5184
[M] 713-962-0885
[H] 713-723-9240

"One good thing about apathy is you don't have to exert yourself to show
you're sincere about it."

------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to