How to select ORDER BY column and RAND() both?

孤者浪人 提交于 2019-11-28 03:57:00

问题


Hello dear friends.

mysql_query("SELECT id FROM tb_table ORDER BY num ASC, ORDER BY RAND() LIMIT 1");

is this coding correct? I want to find all rows ASC num and there can be 1000 rows that num is 1 another 1000 that num is 2. But I want it to sort ASC like 1s firstly and choose one of them randomly.


回答1:


You only need to specify ORDER BY once.

mysql_query("SELECT id FROM tb_table ORDER BY num ASC, RAND() LIMIT 1");


来源:https://stackoverflow.com/questions/7920574/how-to-select-order-by-column-and-rand-both

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!