Hi,
Can't figure out how to do the following
I have a database as follows:
id
email
num_tickets
A couple of random records would look like:
50, [email protected], 4
80, [email protected], 1
85, [email protected], 3
This table has approx 14,000 rows all with a value of num_tickets from 1-4.
What I need to do is select a list of random winners as there are 10,000 tickets available - so I'm not just selecting 10,000 rows from the database.
Does anyone have an idea for this, as I'm stumpted
Thanks
EDIT: just to clarify, I kind of want to select random rows until the sum of num_tickets reaches 10,000.
EDIT EDIT: Think I'm onto soemthing here:
Have got the following working, just struggling to limit the sum of my var amd select random records:
Can't figure out how to do the following

I have a database as follows:
id
num_tickets
A couple of random records would look like:
50, [email protected], 4
80, [email protected], 1
85, [email protected], 3
This table has approx 14,000 rows all with a value of num_tickets from 1-4.
What I need to do is select a list of random winners as there are 10,000 tickets available - so I'm not just selecting 10,000 rows from the database.
Does anyone have an idea for this, as I'm stumpted

Thanks
EDIT: just to clarify, I kind of want to select random rows until the sum of num_tickets reaches 10,000.
EDIT EDIT: Think I'm onto soemthing here:
Code:
SELECT @i:=0;
SELECT id, num_tickets, @i:=@i+num_tickets AS i FROM main_entrant LIMIT 10000;
Code:
SELECT @sumTickets:=0;
SELECT id, num_tickets, @sumTickets:=@sumTickets + num_tickets AS sumTickets FROM main_entrant LIMIT 100
Last edited: