我有三张桌子
ID || login || name || crypted_password || salt
2 || teacher1|| teacher1 || #@@EDGCH || SDWH@##
id||name
3 ||teacher
id || role_id || user_id
2 || 3 || 2
现在从这三个表中我想获取其角色=老师的用户的crypted_password和salt值。
怎么做!!
答案 0 :(得分:1)
您可以使用join
语法根据匹配字段连接表:
SELECT crypted_password, salt
FROM users
JOIN role_users ON users.id = role_uses.user_id
JOIN role ON role_users.role_id = role.id
WHEN role.name = 'teacher'
答案 1 :(得分:0)
像这样加入
SELECT U.*
FROM USER U
JOIN Role_Users RU ON RU.UserID = U.ID
JOIN Role R ON R.ID = RU.Role_ID
WHERE <Your Conditions here>
答案 2 :(得分:0)
select crypted_password,salt
from Users U
inner join Role_users RU on RU.user_id = U.ID
inner join Role R on R.id = RU.role_id
where R.name='teacher'