I'm using MySQL. I have a table which looks like that:
id: primary key
content: varchar
weight: int
What I want to do is randomly select one row from this table, but taking into account the weight. For example, if I have 3 rows:
id, content, weight
1, "some content", 60
2, "other content", 40
3, "something", 100
The first row has 30% chance of being selected, the second row has 20% chance of being selected, and the third row has 50% chance of being selected.
Is there a way to do that ? If I have to execute 2 or 3 queries it's not a problem.
Thanks in advance.