从Mysql获取随机值

时间:2012-11-19 04:33:56

标签: php mysql

如何获取RANDOM User_names。

SELECT a.mod_name, u.user_name, a.id from type a, users u 
WHERE a.id=u.mod_type
ORDER BY mod_type Desc ";

3 个答案:

答案 0 :(得分:4)

您可以使用ORDER BY RAND()

SELECT a.mod_name, u.user_name, a.id
FROM type a, users u
WHERE a.id=u.mod_type
ORDER BY RAND()

答案 1 :(得分:3)

怎么样?

编辑:

select a.mod_name, u.user_name, a.id from type a, users u where a.id=u.mod_type 
order by mod_type DESC, rand();

答案 2 :(得分:2)

Mysql支持RAND()功能

 select a.mod_name, u.user_name, a.id from type a,
 users u where a.id=u.mod_type
 order by RAND(),mod_type Desc ";