Subject Re: [firebird-support] Re: Random Records
Author Ivan Prenosil
>> The Rand() function is fixed in FB2, I think you can use it in FB1.5 too.
>> But the above statement will always read whole table !
>
> The problem I have is that the 'model' provide by mysql and postgres is
> ORDER BY RAND so just replacing with a UDF is not practical. I need to

But e.g. this works "just fine", it will give random record on each execution

SELECT first 1 rdb$relation_name
FROM rdb$relations
ORDER BY Rand();

you just have to use fixed version of udf, and be aware that it does
full table scan (as do other databases too afaik)

Ivan



> 'adjust' the SQL statement to give me something that at least tries to
> return random records. My current thought is changing the ORDER BY RAND
> into a AND unique_id IN ( random_id's ) and populate the list by a
> stored procedure which uses skip with a RAND() - could that work ? Feed
> the Stored Procedure with the number of results required, and get it to
> work out the ranges for skip and rand based on the number of records in
> the table.