Subject | Re: Randomly returning records |
---|---|
Author | Ian A. Newby |
Post date | 2006-05-18T14:02:16Z |
Hi Ed,
Have a stored procedure to return the number of records you want.
Create a new table called random_order with 2 fields id and seed.
index on seed and id.
in your stored procedure:
1. For select first :rows id from random_order order by seed into :id.
2. submit :id
3. delete from random_order where id = :id
4. if not enough rows returned, repopulate random_order and do 1-3 again.
you could repopulate it using something like... insert into
random_order (id, seed) select myid, randomfunction from myquotes table.
This way, each quote will be used once and once only in a given load.
Hope this makes sense.
Regards
Ian
PS. another method would be to use generators...
have the random_order table with and id and an order field.
id is sequential.
use a generator in the stored procedure to get the next quote number.
if no quote is available for that quote number empty the table and
repopulate using the generator value as the starting point for id.
Have a stored procedure to return the number of records you want.
Create a new table called random_order with 2 fields id and seed.
index on seed and id.
in your stored procedure:
1. For select first :rows id from random_order order by seed into :id.
2. submit :id
3. delete from random_order where id = :id
4. if not enough rows returned, repopulate random_order and do 1-3 again.
you could repopulate it using something like... insert into
random_order (id, seed) select myid, randomfunction from myquotes table.
This way, each quote will be used once and once only in a given load.
Hope this makes sense.
Regards
Ian
PS. another method would be to use generators...
have the random_order table with and id and an order field.
id is sequential.
use a generator in the stored procedure to get the next quote number.
if no quote is available for that quote number empty the table and
repopulate using the generator value as the starting point for id.