Mysql random from top 10

I have a mysql query:

SELECT * FROM bigtable WHERE column1='1' ORDER BY column2 DESC LIMIT 10 

And then I put everything in an array and use php to select a random string from this 10 element array.

Is there a way to do this with a single mysql query instead of mysql + php part?

+4
source share
1 answer

After taking the top 10, then take 1 with random:

 SELECT * from ( SELECT * FROM bigtable WHERE column1='1' ORDER BY column2 DESC LIMIT 10 ) T ORDER BY RAND() LIMIT 1 
+6
source

Source: https://habr.com/ru/post/1393040/


All Articles