dimanche 28 février 2016

Mysql - how to random select 1 row in a large repetitive set such that each row had an `equal` chance of selection

I im trying to figure out a simple thing:

how to random select 1 row in a large repetitive set such that each row had an equal chance of selection?

For example, a table of products with each product having multiple entries, I just want to select 1 random. But the 'chance' of that one should not be more than others due to its repetition.

One solution is to get unique list (with GROUP BY) and get RANDOM from this subquery. But for a large dataset, thats not an optimal solution, whcihc is what I need help here.

Thanks.




Aucun commentaire:

Enregistrer un commentaire