查询所有用户及角色,一个用户会有多个角色

select u.*,sr.*
    from users u
    left join sys_user_role sur on sur.userCode=u.id
    left join sys_role sr on sr.roleCode=sur.roleCode

结果

mysql查询出来的某一列合并成一个字段

将用户的角色合并为一个字段

select u.*,GROUP_CONCAT(DISTINCT(sr.roleCode)) 
    from users u
    left join sys_user_role sur on sur.userCode=u.id
    left join sys_role sr on sr.roleCode=sur.roleCode
    group by u.userCode 

结果

mysql查询出来的某一列合并成一个字段

如果出现only_full_group_by错误,请参考链接

 

相关文章:

  • 2021-06-29
  • 2023-02-02
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
  • 2021-07-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2022-12-23
相关资源
相似解决方案