Re: Picking a random row
Date: 1997/11/21
Message-ID: <3475a111.21045332_at_69.0.9.9>#1/1
On Thu, 20 Nov 1997 16:20:39 -0500, roy_at_popmail.med.nyu.edu (Roy Smith) wrote:
>We've got a table with about 600,000 rows, and want to pick a random row
>from it. The brute force method would be to create a new column and fill
>it with sequential numbers, than pick a random integer from 1 to the
>number of rows and select that. There's a number of reasons we don't want
>to do this, mostly because it's a pain to retain the sequence as rows are
>added and deleted. Any better ideas?
>
>--
It's not too difficult to maintain a sequence for inserts. If you don't want to resequence on deletes, you could program the random row selector to loop until it found a sequence number that matches a valid row. Unless you're performing a *lot* of deletes, it's going to get a valid hit the first time round most of the time.
Tim Hall, Indus International (was TSW International)
http://www.tswi.com
http://www.indusgroup.com
Replace domain name with the domain from the first URL before replying via email! Received on Fri Nov 21 1997 - 00:00:00 CET