mysql in子句问题请教

sniper_nie 2016-03-22 10:01:49
1、select role_auth_ids from test_role where role_name='经理' 的执行结果:
+------------+
role_auth_ids
+------------+
1,2,3
2、select auth_name from test_auth where auth_id in (1,2,3)的执行结果:
+------+
auth_name
+------+
商品管理
商品添加
商品编辑
+---------+
但是,将1、2条语句合并后,即select auth_name from test_auth where auth_id in (select role_auth_ids from test_role where role_name='经理'),执行结果只有一条数据,也就是只有“商品管理”一条数据。
SELECT auth_name FROM test_auth WHERE auth_id IN (SELECT replace(concat('''',role_auth_ids,''''),',',''',''') FROM test_role WHERE role_name = '经理 ') 给in子句加上单引号也不行..................
请教各位大神我该如何才能从通过test_role中role_auth_ids查询出对应的test_auth表中的auth_name呢?
...全文
95 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
小灸舞 2016-03-22
  • 打赏
  • 举报
回复
LZ不妨试一下find_in_set

select auth_name from test_auth where find_in_set(auth_id,(select role_auth_ids from test_role where role_name='manager'));

ACMAIN_CHM 2016-03-22
  • 打赏
  • 举报
回复
select a.auth_name from test_role r,test_auth a where find_in_set(a.auth_id,r.role_auth_ids) and r.role_name='经理'

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧