RE: Selecting a random row

2004-12-06 Thread Dathan Pattishall
Pseudo code: $min = SELECT MIN(id) from fortunes; $max = SELECT MAX(id) from fortunes; While (!$row && $count < 3) { $id = rand $max + $min; if ($id > $max) { next; } $row = SELECT * from fortunes where id = $id; $count++ } If ($count >= 3) { return 1st row; } --

RE: Selecting a random row

2004-12-06 Thread Jay Blanchard
[snip] > The way to > enhance this is by selecting an indexed value, such as the following > where `foo` is indexed > > SELECT `foo` FROM fortunes ORDER BY RAND() LIMIT 1 Why does this help? From the MySQL book I have, the reason ORDER BY RAND() is slow is because "for each record in the table a

RE: Selecting a random row

2004-12-06 Thread Joshua Beall
> How many rows do you anticipate that the table will have? Have you > tested this on your server? I would have to bet that if you > have only a few K rows that speed/performance will not be an issue. I doubt I will have more than 100. Perhaps I shouldn't worry about it, then. > The way to > en

RE: Selecting a random row

2004-12-06 Thread Jay Blanchard
[snip] I understand that I can get a random row out of a table by doing something like SELECT * FROM fortunes ORDER BY RAND() LIMIT 1 But I have also been told that this is a very slow operation. I am building a script that will display a random saying, user testimonial, whatever, on a web pag