Hacker News new | past | comments | ask | show | jobs | submit login
ORDER BY RAND() (kneschke.de)
2 points by morphics on Feb 11, 2013 | hide | past | favorite | 1 comment



For selecting a single random row with equal distribution and no need to worry about holes, the following might be simpler:

    SET @var = (SELECT FLOOR(RAND() * COUNT(id)) from random);
    PREPARE statement FROM 'SELECT name FROM random LIMIT ?, 1';
    EXECUTE statement USING @var;
I don't know how well this compares in performance to the examples in the article, but it's certainly easier to comprehend.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: