Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I don't think testimonials would have enticed me to become a member, or even use the site for that matter. I use the site for a learning experience..."

Geography

Where in the world do Tek-Tips members come from?
redoakhg (Programmer)
27 Aug 10 0:33
Hi,

The issue: I need to pull 1 random record form a table to send a message via email to a recipient.

Client can select times and message types.

Once a message has been sent it is flagged and won't be sent again to the client (until all messages within a given category have been sent to the client and then the system reloads the list).

I don't want to sort by message id for several reasons. However, when I run the following query, the recipients receive messages in Alphabetical order.

<cfquery name="NAME" datasource="#clientdsn#" maxrows="1">
Select message,messageid...
From TABLE
Where Messagetypeid = '#checkemails.messagetype#' AND Not Exists
(Select 1 from clienttomessagesent
Where clienttomessagesent.messageid = messages.messageid and clienttomessagesent.clientid = '#checkemails.clientid#')
ORDER BY RAND()
</cfquery>

How do I simply pull a random message from the list?

Driving me nuts.

 
intelwizrd (IS/IT--Management)
27 Aug 10 9:29
Are you trying to send one at a time?  What is the database that you are using?  You could just pull all of the records with the query and then loop through the query one by one to send the message and add the record to know it was sent.  If you just wanted to do it one at a time, you could do this

CODE

<cfquery name="NAME" datasource="#clientdsn#" maxrows="1">
     SELECT TOP 1 message,messageid...
     FROM TABLE
     WHERE Messagetypeid = '#checkemails.messagetype#' AND NOT EXISTS
          (SELECT 1 FROM clienttomessagesent
           WHERE clienttomessagesent.messageid = messages.messageid
           AND clienttomessagesent.clientid = '#checkemails.clientid#')
     ORDER BY RAND()
</cfquery>

Any reason you are not joining the tables together?  Might help the query perform better.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close