Hi,

 

I have the following query:

 

SELECT person FROM people WHERE ORDER BY RAND() * (1 / score) LIMIT 1

 

This returns a person randomly, but the chance of the person being selected
is increased with a higher `score`.

 

What I want to do is make a single query that will return 10 results in this
fashion.

 

Currently I'm doing:

 

for (i = 1; i <= 10; i++) do: SELECT person FROM people WHERE ORDER BY
RAND() * (1 / score) LIMIT 1

 

Which returns a results like:

 

Mike

Sam

Sam

Mike

Mike

Mike

John

Sam

Mike

John

 

This is exactly the result I desire, but programmatically it's not the most
efficient way. I'm guessing using 1 query and using the result set is MUCH
faster, 1 query... 1 result, instead of 10.

 

I have tried:

 

(SELECT person FROM people WHERE ORDER BY RAND() * (1 / score) LIMIT 1)
UNION (X) UNION (X) ... [repeat ten times]

 

This however returns this kind of result:

 

Mike

Sam

John

 

The UNION query seems to remove the repeats, and because this is a
mathematical system this will throw it out.

 

This of course is not what I want :-(. Is there an option that allows
repeats?

 

Cheers,

- Martin

Reply via email to