This is a discussion on Newbie needs help with query within the MySQL Database forums, part of the Database Forums category; Hi, Is there a query which will select x random unique records out of all records and sort them randomly, ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
Is there a query which will select x random unique records out of all records and sort them randomly, but if all records is smaller than x then it chooses all the records and sorts them randomly. e.g choose 3 random unique records out of all records (20) and sort them randomly (5,1,14) , but if there are only 2 records it chooses the 2 records and sorts them randomly (2,1). Thank you in advance, Raj (Newbie) |
|
|||
|
raj <raj@nospam.com> wrote:
> Hi, > > Is there a query which will select x random unique records out of all > records > and sort them randomly, but if all records is smaller than x then it > chooses > all the records and sorts them randomly. > > e.g choose 3 random unique records out of all records (20) and sort them > randomly (5,1,14) , but if there are only 2 records it chooses the 2 > records > and sorts them randomly (2,1). Hmmmz, why didn't my reply show up? Retry: Uniqueness depends on the table. SELECT * FROM tablename ORDER BY RAND() LIMIT max_number -- Rik Wasmus Posted on Usenet, not any forum you might see this in. Ask Smart Questions: http://tinyurl.com/anel |
|
|||
|
Thanks for the answer Rik.
Sorry about the crosspost. Won't happen again. Will read up on crosspost on google now. Raj On Tue, 6 Mar 2007 08:31:17 +0000, Rik wrote (in article <op.tordyf0jqnv3q9@misant>): > raj <raj@nospam.com> wrote: > >> Hi, >> >> Is there a query which will select x random unique records out of all >> records >> and sort them randomly, but if all records is smaller than x then it >> chooses >> all the records and sorts them randomly. >> >> e.g choose 3 random unique records out of all records (20) and sort them >> randomly (5,1,14) , but if there are only 2 records it chooses the 2 >> records >> and sorts them randomly (2,1). > > Hmmmz, why didn't my reply show up? Retry: > Uniqueness depends on the table. > > SELECT * FROM tablename ORDER BY RAND() LIMIT max_number > > |