MySQL: Can you specify a random limit?

前端 未结 2 867
刺人心
刺人心 2021-01-27 10:52

Is there a way to randomize a limit number in SQL (MySQL)?

What I\'d like to be able to do is get a random number of results in a query to use in an insertion subquery w

2条回答
  •  梦如初夏
    2021-01-27 11:36

    For MySQL specifically:

    SET @i = 0;
    SELECT * 
    FROM users
    WHERE (@i:=@i+1) < RAND()*1000
    ORDER BY RAND();
    

提交回复
热议问题