Devi solo specificare ORDER BY una volta. mysql_query("SELECT id FROM tb_table ORDER BY num ASC, RAND() LIMIT 1");