First off your second query won't work because you aren't grabbing the top 10 items and then randomizing them and grabbing 4. You are instead grabbing the top 10 randomized items and then grabbing 4th-10th ranked results.
If you are fine with the latter than your case than your original query is statistically correct. Grabbing any 4 records from the result set will give you statistically the same results.
If you instead need to order these specifically and then grab 4 of the top 10 results at random you need to do the following.
You can do this a two, and possibly more, different ways.
First way is to query for the first 10 rows and then use a randomized array in PHP to pull for records from the result set while iterating through.
The second way involves nesting queryies:
Code: Select all
FROM (SELECT *
ORDER BY <what ever prioritizes these records>
LIMIT 10) x
ORDER BY RAND()