Subject Re: [firebird-support] Re: Random Records
Author Alexandre Benson Smith
Ivan Prenosil wrote:

>The Rand() function is fixed in FB2, I think you can use it in FB1.5 too.
>
>
good news

>But the above statement will always read whole table !
>
>
yep.

To minimize network traffic FIRST/SKIP could be used. but the table will
always use a natural plan :-(

>Lester, do you need "single select statement" solution ?
>Can you afford to create generator that would remember last used ID
>on each request ? Or just simply do something like
> select first 1 * from ... where id > gen(last_id, 7) order by id
>and reset generator if no record is returned ...
>
>
Another approach.

1.) Create a column called Random on that table, do and update to random
sort the records.

2.) update MyTable set Random = Rand()

Then use

3.) Select first 10 from MyTable where Random <> 0 order by Random

4.) present it to the user

5.) Mark those records as viewed updating the Random column to 0

When run out of records go to step 2

>Ivan
>
>
see you !

--
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br