If you don't want to use a temporary table, an alternative would be to select the rows along with the sum of the number of tickets purchased (with the rows ordered in some arbitrary but consistent way). Then, generate a random integer in the range [0, sum of the number of tickets purchased). Then, iterate over the rows retrieved, adding the number of tickets purchased for that row to a cumulative sum, until the sum exceeds the random integer. At that point, the current row's corresponding user is the random winner.