> At 08:59 PM 2/27/2010, you wrote:
>>Hello everyone,
>>
>>How would I select a random row that changes daily?
>>
>>Thanks
>
> The common way would be to do:
>
> select * from table order by rand() limit 1;
>
> You can of course add a Where clause to select only those rows that were
> added today.
>
> select * from table where Log_Date=Date(Now()) order by rand() limit 1;
>
> This works fine as long as there are not too many dates to sort. Otherwise
> you will need to use an autoinc column and choose one of those randomly.
> This is not as easy as it looks because the sequence may have holes in it
> and may not be in the proper sequence.
>
>
> Mike
>
Thanks for the reply Mike but the "common way" you mentioned didn't do
what I wanted. I did some searching on Google and found the following
PHP/MySQL code which seems to do what I want...
$query = "SELECT * FROM table ORDER BY rand(" . date("Ymd") . ") LIMIT 1";
...It selects a random row that changes on a daily bases.
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[email protected]