【发布时间】:2013-09-17 09:46:36
【问题描述】:
我有两个表 - 用户和模块。
在模块表中,我有两列 - module_id 和 module_name。
用户表有一个名为 user_modules 的列,我在其中存储了他可以以 csv 格式访问的模块。
例如。模块表中有两个模块
module_id module_name
1 Manage Books
2 Manage Videos
典型用户的 user_modules 列(在用户表中)看起来像这样
user_modules
1,2
现在我用来获取 module_name 的查询是
"Select module_name from modules where module_id in (Select user_modules from user where user_id = 1)" - 输出:管理书籍
这仅返回第一个模块的名称。
另一方面,这些查询工作得非常好 -
“从 module_id 在 (1,2) 中的模块中选择 module_name” - 输出:管理书籍、管理视频
“从 user_id = 1 的用户中选择 user_modules” - 输出:1,2,3
如何在单个查询中获取所有模块名称?
【问题讨论】:
标签: mysql