select daily random

select daily random

am 28.02.2010 03:59:58 von Jason Carson

Hello everyone,

How would I select a random row that changes daily?

Thanks



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org

Re: select daily random

am 28.02.2010 04:03:59 von Jason Carson

....I am using PHP 5.2

> Hello everyone,
>
> How would I select a random row that changes daily?
>
> Thanks
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=jason@jasoncarson.ca
>
>



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org

Re: select daily random

am 28.02.2010 08:01:55 von mos

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


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org

Re: select daily random

am 28.02.2010 19:14:07 von Jason Carson

> 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/mysql?unsub=gcdmg-mysql-2@m.gmane.org