这是我的查询运作良好,但想在其中添加另一个条件,但它给出错误不唯一的表/别名:'用户'
这是我的代码
$query = 'select group_concat(DISTINCT evaluation_section. section_name) as allowed_sections from evaluation_section
join section_permissions on (section_permissions.section_id = evaluation_section.section_id )
join users on ( users.user_id = section_permissions.user_id )
join users on ( users.user_id = section_permissions.assigned_for )
where users.user_id = '.$user['user_id'];
还希望从用户表中选择名称,然后在(users.user_id = section_permissions.assigned_for )
请帮帮我
这是我编辑的文字
这是我完整的工作查询
$q = 'select group_concat(DISTINCT evaluation_section. section_name) as allowed_sections from evaluation_section
join section_permissions on (section_permissions.section_id = evaluation_section.section_id )
join users on ( users.user_id = section_permissions.user_id )
where users.user_id = '.$user['user_id'];
但我希望它从users表中选择名称,然后将其与users.user_id = section_permissions.assigned_for
匹配,以便获得assign_for id name的名称
和group_concat之前一样,我使用users.name然后它的工作,但它显示名称users.user_id = section_permissions.user_id
,但我想显示er_id的名称)
users.user_id ='。$ user [' user_id'];
但我希望它从users表中选择名称,然后将其与users.user_id = section_permissions.assigned_for
匹配
在同一个查询中,因为其中两个不起作用
答案 0 :(得分:3)
尝试这样做:
$query = 'select group_concat(DISTINCT evaluation_section. section_name) as allowed_sections from evaluation_section
join section_permissions on (section_permissions.section_id = evaluation_section.section_id )
join users u1 on ( u1.user_id = section_permissions.user_id )
join users u2 on ( u2.user_id = section_permissions.assigned_for )
where u1.user_id = '.$user['user_id'];
因为您正在加入"用户"表格两次,你必须为它们提供唯一的别名。