Hmm, no reading comprehension points for me. I managed to read Steve's
message the first time without realizing that he only wanted one row.
Here's another approach. I'm curious about the performance implications:
SELECT @lines:=COUNT(id) FROM table;
SET @rand=CEILING(RAND()*@lines);
SELECT
At 11:39 PM 2/10/2001 -0800, Stephen Waits wrote:
>Never mind on the "it doesn't work on my system" more like it didn't
>work on my brain :) Works fine.
Oh, phew.
>Theoretically it could be as fast as Carsten's method couldn't it? If
>it hit a record on the first shot? Otherwise it's pounding
Could you do something like:
CREATE TEMPORARY TABLE temptable (
pk INTEGER,
rand INTEGER
);
INSERT INTO temptable SELECT yourpk,Rand() FROM yourtable;
SELECT yourtable.* FROM yourtable,temptable WHERE pk=yourpk ORDER BY rand;
DROP TABLE temptable;
That might be quicker than your current a