sql多表连接

下面演示一个三表连接查询。

用户表、部门表、用户部门关联表

select a.id as userId,dept_id,c.name as deptName
from user as a
left join user_dept as b
on a.id=b.user_id
left join department as c
on b.dept_id=c.id;

在这里插入图片描述

用户表、角色表、用户角色关联表

select a.id as userId,c.name as roleName
from user as a
left join user_role as b
on a.id=b.user_id
left join role as c
on b.role_id=c.id;

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43606158/article/details/107337390