'on子句'中的未知列

时间:2014-02-21 20:50:08

标签: mysql sql

查询对我来说非常正确。在查找时,查询中似乎存在优先级问题。

问题出在这一行 - group_membership_settings.group_id = groups.id

'on clause'

中的未知列groups.id
 SELECT SQL_NO_CACHE `groups`.`name` AS `profile_name`, ( 
        SELECT IF(
          group_membership_settings.max_limit, 
          group_membership_settings.max_limit > ( 
            SELECT COUNT(connection_memberships.id) FROM connection_memberships
            WHERE connection_memberships.type = 'Connection::MenteeMembership' 
            AND connection_memberships.group_id = groups.id
          ), 1) 
        FROM programs 
          INNER JOIN roles ON roles.program_id = programs.id AND roles.name = 'student'
          LEFT JOIN group_membership_settings ON group_membership_settings.group_id = groups.id AND group_membership_settings.role_id = roles.id
        WHERE programs.id = groups.program_id
    ) AS `available_to_join` FROM `groups` 

1 个答案:

答案 0 :(得分:0)

表(别名)groups不在 范围内。

您只能引用本地查询中表格中的列,即programsrolesgroup_membership_settings

我不知道你的意图是什么,但你可能还必须在内部查询中加入groups