问题描述
- mysql in子句问题请教
-
1、select role_auth_ids from test_role where role_name='经理' 的执行结果:
+------------+
role_auth_ids
+------------+
1,2,32、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='经理'),执行结果只有一条数据,也就是只有商品管理一个数据。这是why?
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呢?
解决方案
你将你的test_auth 和 test_role 表的关于这几个字段的具体数据列检索结果列一下吧
解决方案二:
查询语句好乱。那几个id是varchar2类型的,需要每个id上都用单引号包含。应该这样 in ('1','2','3')
解决方案三:
检查 select role_auth_ids from test_role where role_name='经理' 这条语句的查询结果
解决方案四:
用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='经理'))
解决方案五:
看下你建的表中的字段的数据类型是否一致 sql应该是没有问题的
解决方案六:
'经理 ' 经理两字后有空白字符串