Solved

mysql query question

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

706 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now