i want to Find out role.id
by searching role.name
and then retrieve all users by matching their user_id = founded role.id
Asked
Active
Viewed 42 times
-3

Mukesh Kumar
- 65
- 5
-
1Have you tried something yet? – Tim Biegeleisen Feb 03 '17 at 04:06
-
what you trying to do – Shibon Feb 03 '17 at 04:06
-
select * from user join Role on Role.id=user.role where role.name='provider'; – JYoThI Feb 03 '17 at 04:14
-
When composing a good Stack Overflow question do try and post the result of `SHOW CREATE TABLE` and not screenshots that often contain nothing but irrelevant cutter like action links we can't click. – tadman Feb 03 '17 at 05:43
2 Answers
1
Below query will work:
select id,user_id,username from (select id from Role where name = 'provider') as t
join
user u on t.id = u.role

Nisse Engström
- 4,738
- 23
- 27
- 42

Chintan Udeshi
- 362
- 1
- 8
-
you have used sub-query but i was trying using join only i got it. – Mukesh Kumar Feb 03 '17 at 05:48
0
SELECT * FROM users INNER JOIN role on user.role = role.id WHERE role.name = 'provider'

Mukesh Kumar
- 65
- 5
-
1When giving an answer it is preferable to give [some explanation as to WHY your answer](http://stackoverflow.com/help/how-to-answer) is the one. – Stephen Rauch Feb 03 '17 at 16:43