You are here: Re: Find random stuff « PHP SQL « IT news, forums, messages
Re: Find random stuff

Posted by J.O. Aho on 01/10/06 02:22

Jim Michaels wrote:
> OOPS! I was wrong. you *can* use RAND() in an ORDER BY clause. the manual
> states:
> You can't use a column with RAND() values in an ORDER BY clause, because
> ORDER BY would evaluate the column multiple times. As of MySQL 3.23, you can
> retrieve rows in random order like this:
>
>
> mysql> SELECT * FROM tbl_name ORDER BY RAND();
>
> ORDER BY RAND() combined with LIMIT is useful for selecting a random sample
> of a set of rows:
>
>
> mysql> SELECT * FROM table1, table2 WHERE a=b AND c<d
> -> ORDER BY RAND() LIMIT 1000;
>
> Note that RAND() in a WHERE clause is re-evaluated every time the WHERE is
> executed.

This don't fit the OP, as instance with a higher Rated_Sum should be picked
more often than one with a low value, the way you suggest here would give each
row the same chance to be in the top of the list.

If wanting to get the results as in the first post, then procedure (mysql5) is
the only way to get it, without using help of PHP, if not be that strict, then
you can do it with subselects (mysql4) as Stefan suggested.


//Aho

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация