2 messages in com.mysql.lists.bugsRE: ORDER BY with RAND() doesn't work
FromSent OnAttachments
Sascha Mantscheff12 Jun 2000 02:46 
jason12 Jun 2000 03:16 
Subject:RE: ORDER BY with RAND() doesn't work
From:jason (jas@bigpond.com)
Date:06/12/2000 03:16:19 AM
List:com.mysql.lists.bugs

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1

Sascha Mantscheff writes ..

Try the statement SELECT *, RAND() AS r FROM myTable ORDER BY r;

The table will not be sorted by the random value field. Do you know why?

makes sense to me .. how would the SELECT function know what all the RAND() generated values are going to be ahead of time

my guess is that the RAND() executions are done as each line is generated .. so with no context MySQL is unable to do the sort

you could use a temporary table if you're post 3.23 .. or create a drop a table if you're pre 3.23

- -- jason - elep@squirrelgroup.com -

-----BEGIN PGP SIGNATURE----- Version: PGPfreeware 6.5.1 for non-commercial use <http://www.pgp.com>

iQA/AwUBOUVFKDYpBpopJvWUEQKNrQCfYYZCn3YUkMXqykSNXKAr8N8iol0AnR/0 esye4OiWdU0HD2AgZZzk7XKh =ZfQ8 -----END PGP SIGNATURE-----