Re: MySQL question
| From: | pierre-yves | Date: | Thu, 11 Oct 2001 14:32:04 +0000 |
| Subject: | Re: MySQL question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-70811@lists.php.net to get a copy of this message | ||
From www.mysql.com
You can't use a column with RAND() values in an ORDER BY clause, because
ORDER BY would evaluate the column multiple times. In MySQL Version 3.23,
you can, however, do: SELECT * FROM table_name ORDER BY RAND() This is
useful to get a random sample of a set SELECT * FROM table1,table2 WHERE a=b
AND c<d ORDER BY RAND() LIMIT 1000. Note that a RAND() in a WHERE clause
will be re-evaluated every time the WHERE is executed.
// ========
So if you have mysql version 3.23 you can do it directly in your query, if
you don't have this version, I don't know,
I would do it in php with LIMIT ??
hope it helps...
py
----- Original Message -----
From: "Mitja Pagon" <mitja@hatchbit.com>
To: <php-general@lists.php.net>
Sent: Thursday, October 11, 2001 10:13 AM
Subject: [PHP] MySQL question
> Hello!
>
> What is the simplest most efficient way to get a random record from a
MySQL
> database?
>
> Thanks,
>
> Mitja Pagon
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>