Hi!
On Jul 07, Scott A. Hammond, Sr. wrote:
> I am running MySQL 3.23.54.
>
> Query: SELECT column1, column2, RAND() AS column3 FROM table WHERE column2
> IS NOT NULL ORDER BY column3 LIMIT 10;
>
> I am running this query within a PHP page that uses mysql_connect. More
> then 9 out of 10 times I get the first 10 rows of the database in order,
> i.e. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. Every once in a while, I get it in a
> different order, however, very rarely. This exact PHP file works on another
> server which is running an earlier version of MySQL (3.23.41). Moved to
> this server, I can't seem to pull 10 random rows from the database.
>
> I've tried initializing RAND with a number but that didn't help. I'd
> consider just generating the random numbers myself and selecting the rows,
> however, I need the WHERE column2 IS NOT NULL as part of the query so it
> needs to be randomized within MySQL.
>
> I've altered the program to echo column3 (the random number) and I get a
> different set of numbers each time so it isn't a cached result or anything
> like that. The numbers are simply coming out in the same order as the rows
> are originally in the database on most attempts.
>
> I tried the query from command line (MySQL client) and the results seem to
> be more randomized then when called via PHP, however, I'm having a hard time
> finding any clues on either end (MySQL or PHP) as to why I'm not getting
> random results. This query works on my other servers (which are running
> earlier versions of MySQL).
>
> Any thoughts or help is appreciated.
>
> Scott
According to the manual:
Changes in release 3.23.56 (13 Mar 2003):
...
* Better `RAND()' initialisation for new connections.
...
Regards,
Sergei
--
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Sergei Golubchik <[EMAIL PROTECTED]>
/ /|_/ / // /\ \/ /_/ / /__ MySQL AB, Senior Software Developer
/_/ /_/\_, /___/\___\_\___/ Osnabrueck, Germany
<___/ www.mysql.com
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]