List:General Discussion« Previous MessageNext Message »
From:Rob Wultsch Date:May 2 2008 12:58am
Subject:Re: Age old order by rand() issue
View as plain text  
>  SELECT storage_path, image_md5, id
>   FROM images
>   JOIN (SELECT CEIL(RAND() * (SELECT MAX(id) FROM images WHERE approved =
> 1)) AS id) AS r2 USING (id)
>    WHERE approved = 1;
>
>  I really do not get this, SELECT CEIL(RAND() will always return 1 will it
> not?  Any idea why I get an empty result set at times?

http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_rand
So CEIL(RAND() ) would always be 1.
My guess is you have is that you have hole(s) in your data set.

For the record you are not doing CEIL(RAND() ), your doing CEIL(RAND()
* (SELECT MAX(id) FROM images WHERE approved => 1))

-- 
Rob Wultsch
wultsch@stripped
wultsch (aim)
Thread
Age old order by rand() issueScott Haneda2 May 2008
  • Re: Age old order by rand() issueRob Wultsch2 May 2008
    • Re: Age old order by rand() issueRob Wultsch2 May 2008
    • Re: Age old order by rand() issueScott Haneda2 May 2008
      • Re: Age old order by rand() issueRob Wultsch2 May 2008