Hi Stuart,

Good solution! I didn't even think of that. :-) Interestingly, and FYI,
it doesn't work correctly on 4.1.0 (ignores the LIMIT). Hopefully it's a
known bug that's been fixed in 4.1.1.

4.1.0 does work correctly though using derived tables as John Bonnett
suggested:

SELECT * FROM
(SELECT * FROM table ORDER BY RAND() LIMIT 20) tbl_alias
ORDER BY col1


Matt


----- Original Message -----
From: "Stuart M. Robinson"
Sent: Tuesday, October 07, 2003 6:00 PM
Subject: Re: MySQL: Ordering Random Records


> Folks,
>
> Urgh, you know that feeling when you've burnt lots of cycles trying to
> come up with a clever solution to a problem only to find the answer is
> easy?  We've been thrashing through ideas on how to order random
records
> that have included temporary tables and writing data in and out of
tables,
> when in fact all that's needed is some union syntax:
>
> rsTest.Source = "(SELECT record1, record2, record3 FROM
MyDatabase.MyTable
> ORDER BY RAND() LIMIT 20) ORDER BY record1 ASC;"
>
> And that's all there is to it!  No permission or thread problems
whatsoever.
>
> Many thanks to all who helped out.
>
>
> Stuart.


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to