List:General Discussion« Previous MessageNext Message »
From:Michael Monashev Date:July 20 2005 4:09pm
Subject:Re: random rows selection
View as plain text  
Hello

GP> Similar questions have been asked before. For example:
GP>   http://lists.mysql.com/mysql/184088

Thank you. I found something interesting:

SELECT @rand_id:= CAST( 1 + MAX(id)*RAND() AS UNSIGNED) FROM history;
SELECT * FROM history WHERE id >= @rand_id LIMIT 1;

But this query can return empty results, if we use it with WHERE:

SELECT @rand_id:= CAST( 1 + MAX(id)*RAND() AS UNSIGNED) FROM history;
SELECT col1, col2 FROM table WHERE id >= @rand_id AND col3=123 LIMIT 5;
                                                  ^^^^^^^^^^^^
:-(

Sincerely,
Michael,
 http://xoib.com/ http://3d2f.com/
 http://qaix.com/ http://ryxi.com/
 http://gyxe.com/ http://gyxu.com/
 http://xywe.com/ http://xyqe.com/



Thread
random rows selectionMichael Monashev20 Jul
  • Re: random rows selectionGleb Paharenko20 Jul
    • Re: random rows selectionMichael Monashev20 Jul
      • Re: random rows selectionGleb Paharenko21 Jul
  • Re: random rows selectionChris Knipe20 Jul
  • Re: random rows selectionNuno Pereira21 Jul