4

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 ";
6
  • how many username do you want from a single select? Commented Nov 19, 2012 at 4:44
  • You want one random user name for each type? Commented Nov 19, 2012 at 4:46
  • All usernames present in users table. @ariefbayu Commented Nov 19, 2012 at 4:47
  • Random user name available in users table for each type. @Jack Commented Nov 19, 2012 at 4:49
  • let me wrap: you want to show ALL type with only one random username for each type? Commented Nov 19, 2012 at 4:49

3 Answers 3

4

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()
Sign up to request clarification or add additional context in comments.

2 Comments

Want order by mod_type Desc as it.@ariefbayu
Thank You ariefbayu for your effort. @ariefbayu
3

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

?

1 Comment

@AvinVarghese, it will obviously fetch all mod types as you dont have any condition to filter out mod types in your query. Try reversing the order by part to, order by mod_type DESC, rand()
2

Mysql supports RAND() function

 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 ";

2 Comments

Want order by mod_type Desc as it.@akhilraj-n-s
Thank You Akhilraj for your effort. @Akhilraj N S

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.