Du behøver kun at angive ORDER BY én gang. mysql_query("SELECT id FROM tb_table ORDER BY num ASC, RAND() LIMIT 1");