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
Solved

mysql query question

Posted on 2002-06-19
3
167 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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

856 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