2017-02-03 30 views
-2

我想通过搜索role.name找出role.id,然后通过匹配检索所有用户的SQL查询其user_id = founded role.id什么将是这个

enter image description here

+1

你尝试过什么吗? –

+0

你想要做什么 – Shibon

+0

select * from用户加入Role.id = user.role其中role.name ='provider'; – JYoThI

回答

1

下面的查询将工作:

select id,user_id,username from (select id from Role where name = 'provider') as t 
join 
user u on t.id = u.role 
+0

你已经使用子查询,但我试图使用连接只有我明白了。 –

0
SELECT * FROM users INNER JOIN role on user.role = role.id WHERE role.name = 'provider'
+1

当给出答案时,最好给出[关于为什么你的答案的解释](http://stackoverflow.com/help/how-to-answer)。 –