sql 知道user表 ID字段,然后查出后面关联表的字段

2024-12-15 23:12:14
推荐回答(2个)
回答1:

select t1.id as userid,t2.id as roleid,t2.name as rolename,t3.name as permissonname
from user t1 left join role t2 on t1.id=t2.id
left join Permission t3 on t2.id=t3.id
where t1.id=1

回答2:

select a.UserID , b.Roleid,b. RoleName, c. PermissionName from user a
left join Role b on a.id=b.id
left join Permission c on b.id=c.id
大概就是这样