Bluehost.com Web Hosting $6.95

Newbie needs help with query

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, ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-06-2007
raj
 
Posts: n/a
Default Newbie needs help with query

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)

Reply With Quote
  #2 (permalink)  
Old 03-06-2007
Rik
 
Posts: n/a
Default Re: Newbie needs help with query

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
Reply With Quote
  #3 (permalink)  
Old 03-06-2007
raj
 
Posts: n/a
Default Re: Newbie needs help with query

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
>
>



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:29 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0