开发者

How can I SELECT 16 records at random from a range of rows in MySQL?

开发者 https://www.devze.com 2022-12-09 05:33 出处:网络
I want to display a list of 16 of the most popular items in my database, but I want that list to be different every time.So from say, the top 50 downloa开发者_Go百科ded items, choose 16 at random and

I want to display a list of 16 of the most popular items in my database, but I want that list to be different every time. So from say, the top 50 downloa开发者_Go百科ded items, choose 16 at random and return that in the result. Is that possible with just one query?


SELECT * 
    FROM (SELECT FROM table ORDER BY download_no DESC LIMIT 50) AS new_table
    ORDER BY RAND() 
    LIMIT 16


Here is a webpage discussing this problem: http://akinas.com/pages/en/blog/mysql_random_row/

HTH


ORDER BY RAND()

0

精彩评论

暂无评论...
验证码 换一张
取 消