Solved

mysql query question

Posted on 2002-06-19
3
169 Views
Last Modified: 2010-08-05
I have an myql table which holds the names and email addresses of visitors to my site that have entered a competition, Now that the competition is closing I need to randomly select 3 winners from the database.  

I figured this could probably be done with a simple sql query?

thanks in advance

table structure below:

# Database : `board`
# --------------------------------------------------------

#
# Table structure for table `cd_submissions`
#

CREATE TABLE cd_submissions (
  user_email varchar(255) NOT NULL default '',
  user_name varchar(100) NOT NULL default '',
  UNIQUE KEY cd_submissions_ux1  (user_email)
) TYPE=MyISAM;

0
Comment
Question by:1524
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
Hamlet081299 earned 200 total points
ID: 7094286
Here's a simple query that should do the trick ...

select user_email, user_name
from tablename
order by Rand()
limit 3

0
 
LVL 5

Expert Comment

by:Hamlet081299
ID: 7094297
oops...

select user_email, user_name
from cd_submissions
order by Rand()
limit 3

p.s. This will return a different result each time it is run ... I hope that is what you wanted
0
 

Author Comment

by:1524
ID: 7094300
thanks for your help, much appreciated
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question