我收到错误ERROR不唯一的表/别名

时间:2016-06-17 12:14:12

标签: mysql

我无法弄清楚这个查询有什么问题:

SELECT 
    user_master.user_id,
    user_master.business_id,
    user_master.user_name,
    user_master.lastname,
    user_master.user_type_id,
    user_master.group_id,
    GROUP_CONCAT(group_master.group_name) GroupName
FROM
    user_master
        JOIN
    group_master ON FIND_IN_SET(group_master.group_id,
            user_master.group_id)
        JOIN
    group_master ON group_master.group_id = user_master.group_id AND group_master.business_id = user_master.business_id
WHERE
    user_type_id = '3' AND user_master.business_id = '248' AND user_master.email_id <> '' AND user_master.user_name <> 'Test' AND user_master.lastname <> 'Learner' AND user_master.is_deleted = '0' AND user_master.is_active = '1'
GROUP BY user_master.user_id
order by user_master.user_name ASC

执行后,我收到错误ERROR Not unique table/alias

1 个答案:

答案 0 :(得分:0)

您要加入group_master两次,因此您需要为每个名称添加不同的名称。在您的情况下,您有两个同名的关系无效。为它们定义不同的别名,以使它们在查询中唯一。