MySql randomize the last 10 rows

后端 未结 2 1653
面向向阳花
面向向阳花 2021-01-19 03:33

I need help on how to randomize the last 10 rows of MySql records.

$mysqld = mysql_query(select * from table where amount > amount2 and code = \'$code\' o         


        
2条回答
  •  心在旅途
    2021-01-19 04:18

    Try....

    SELECT * FROM (SELECT * FROM yerTable ORDER BY id DESC LIMIT 10) AS tmp ORDER BY RAND() LIMIT 1
    

    Obviously replace id with any other distinct column if preferred.

提交回复
热议问题