In the event you do not wish to select all the full row for all records, you
could just grab all the keys in the first query and come around again for
the full row:

<cfquery name="qGetKeys">
    select    key
    from    table
</cfquery>

<cfset randomKey = qGetKeys[RandRange(1,qGetKeys.RecordCount)].key>

<cfquery name="qGetRandomRecord">
    select    *
    from    table
    where    key = '#randomKey#'
</cfquery>

Which would be infinitely faster if you're dealing with large text fields or
something.

Have fun! ;-)

----- Original Message -----
From: "Jason Stiefel" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Thursday, October 05, 2000 10:13 PM
Subject: Re: Random Record


> kev-
>
> <cfquery name="myquery">
>     select    myfields
>     from    mytable
> </cfquery>
>
> <!--- (i.e. select all the records. this wouldn't be recommended in a
really
> large table!) file://--->
>
> <cfset intRecord = RandRange(1,myquery.RecordCount)>
>
> <cfoutput>#myQuery[intRecord].field#</cfoutput>
>
> You can treat any query as if it were an array.
>
> ----- Original Message -----
> From: <[EMAIL PROTECTED]>
> To: "CF-Talk" <[EMAIL PROTECTED]>
> Sent: Thursday, October 05, 2000 7:49 PM
> Subject: Random Record
>
>
> > How could i select a random record from a table?
> >
> > Like to set my query as
> >
> > <cfquery datasource="mine" name="selectrandomrecord">
> > SELECT *
> > FROM Table
> > WHERE RecordID = ??????
> > <cfquery>
> >
> > Anyone know how to do this?
> >
> > thanks
> >
> > kev
>
> --------------------------------------------------------------------------
> ----
> > Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
> > To Unsubscribe visit
> http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
> send a message to [EMAIL PROTECTED] with 'unsubscribe' in
> the body.
> >
> >
>
> --------------------------------------------------------------------------
----
> Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
> To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.
>
>

------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to