The goal of this query is to pick 10 winners from a mysql database of entries into a contest. The columns are "product_id", "uid" and "winner".
Winner is always 0 (for now, as winners haven't been picked), uid is a unique index (one entry per person), and product_id is one of 10 different product id's. To enter the contest, the user logged in, and chose which one of the 10 products they wanted to win.
There are 1000 rows in the database, with about 100 rows each for each of the 10 product id's.
I'd like to have one query that chooses one random entry for each of the 10 different product id's. The query below is selecting 10 random entries, but some of the product id's are the same.
SELECT DISTINCT product_id, uid FROM database.table WHERE winner = 0 ORDER BY RAND( ) LIMIT 0 , 10
How can I improve this query to work in the way I need?