Rob@TH wrote:
> Hmm still nothing :/
> Any other possibilities?
[ Selecting a random entry from a database ]
Generally this is a hard problem. Ordering by rand() is really wasteful
because the DB has to select *all* entries, order them, and then pick one.
There are more efficient solutions available if you know the domain of the
problem well. E.g. if you use an auto-increment column as a primary key,
you can do something like (two steps here):
select max(pk), min(pk) from table;
<in your app, select a random value between the two>
select * from table
where pk >= randval - fudge
and pk <= randval + fudge
limit 1;
(This fudge is to handle the case of holes in the primary key sequencing).
It works relatively satisfactorily as a randomizer, unless you are
interested in mathematically precise random distributions (:-/).
--
Shankar.
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php