Hello,
I am trying to pull a random record out of a table with 200 some rows. However, I need the randomness to be weighted.
The table has the following structure:
name VARCHAR
weight INT
Currently, I have SQL that looks like this:
SELECT * FROM tb ORDER BY RAND() LIMIT 1
However, some name columns have higher weight values than others, and I need to have a name column that has a weight of 1000 come up more frequently than a column that has a weight of 5.
Is there a way to do this via SQL only? Or do I have to resort to array manipulation in PHP?
Thanks for your help!
I am trying to pull a random record out of a table with 200 some rows. However, I need the randomness to be weighted.
The table has the following structure:
name VARCHAR
weight INT
Currently, I have SQL that looks like this:
SELECT * FROM tb ORDER BY RAND() LIMIT 1
However, some name columns have higher weight values than others, and I need to have a name column that has a weight of 1000 come up more frequently than a column that has a weight of 5.
Is there a way to do this via SQL only? Or do I have to resort to array manipulation in PHP?
Thanks for your help!