Reputation: 277
I am trying to select the three rows that have the highest scores. Obviously I can use a simple things such as:
SELECT * FROM myTable ORDER BY myscore DESC LIMIT 3;
But what I also want is an easy way for this to return only one of these three rows randomly. Normally I just do an ORDER BY rand(), but what is the cleanest way to add the constraint that it has to be a random one from only the top 3 scored rows?
Thanks!
Upvotes: 2
Views: 110
Reputation: 454020
SELECT * FROM
(
SELECT * FROM myTable ORDER BY myscore DESC LIMIT 3
) Top3
ORDER BY RAND() LIMIT 1;
Upvotes: 4