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

Hello dear friends.

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

Is this coding right? I want to find all ASC lines num and there can be 1000 lines, the number of which is 1 another 1000, that num is 2. But I want him to sort the ASC first as 1s and select one of them randomly.

+5
source share
1 answer

You only need to specify ORDER BYonce.

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

All Articles