If you want to get only one record you can use this code:

<CFQUERY NAME="myquery" DATASOURCE="mydatabase">
SELECT      *
FROM         TABLE
</CFQUERY>
<cfset pos = RandRange(1, myquery.recordcount)>
<cfoutput query="myquery" startrow="#pos#" maxrows="1">
..
..
..
</cfoutput>

Note: you have to initialize the rand function.

Alejandro Mozo Quesada
Sistemas / Programaci�n
http://www.tiza.net
educar divirtiendo

----- Original Message -----
From: "Tony" <[EMAIL PROTECTED]>
To: "CF-Server" <[EMAIL PROTECTED]>
Sent: Monday, April 09, 2001 10:24 AM
Subject: order by random


> Hello Everyone,
>
> Is there a way to sort a column in random order? I thought something like:
>
> SELECT * FROM MyTable
> WHERE
>     MyVariable='#myvalue#'
> ORDER BY RANDOM
>
> would output something like
>
> 1
> 2
> 3 the first time
>
> and then
>
> 1
> 3
> 2 (varying in order)
>
> but all it does is say error... If there isn't a way built into cf/sql to
do this does someone have their own method that they'd be willing to share?
>
> Thanks,
> Tony Hicks
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
------------------------------------------------------------------------------
To unsubscribe, send a message to [EMAIL PROTECTED] with 
'unsubscribe' in the body or visit the list page at www.houseoffusion.com

Reply via email to