• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

mysql query question

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
1524
Asked:
1524
  • 2
1 Solution
 
Hamlet081299Commented:
Here's a simple query that should do the trick ...

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

0
 
Hamlet081299Commented:
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
 
1524Author Commented:
thanks for your help, much appreciated
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now