Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

mysql query question

Posted on 2002-06-19
3
Medium Priority
?
172 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 800 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

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 …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

618 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