Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Random values from Mysql

Tags:

php

mysql

How to fetch 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 ";
like image 859
Avin Varghese Avatar asked Jan 16 '23 00:01

Avin Varghese


2 Answers

You can use ORDER BY RAND() for that:

SELECT a.mod_name, u.user_name, a.id
FROM type a, users u
WHERE a.id=u.mod_type
ORDER BY RAND()
like image 167
ariefbayu Avatar answered Jan 17 '23 17:01

ariefbayu


What about

EDIT:

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();

?

like image 25
WatsMyName Avatar answered Jan 17 '23 17:01

WatsMyName