On Mon, 1999-09-20 10:02:21 -0500, Joel Chippindale wrote:
> I would like to choose a record at random from a MySQL database.
> I thought that maybe I could order the results of a select using a
> RAND column so that a random record is returned first but the MySQL
> manual specifically says that this will not work.
I work-around for versions of MySQL before V3.23 is:
SELECT *, id*0+RAND() AS r FROM table ORDER BY r LIMIT 5;
where "id" is some field of your table.
| The problem is that without the 'id' MySQL 3.22 thinks that 'r' is
| an constant and will automaticly remove it from the ORDER BY clause.
Martin Ramsch <m.ramsch@stripped> <URL: http://home.pages.de/~ramsch/ >
PGP KeyID=0xE8EF4F75 FiPr=52 44 5E F3 B0 B1 38 26 E4 EC 80 58 7B 31 3A D7