开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜