2014-02-21 66 views
0

查詢對我來說看起來非常正確。在查找時,查詢中似乎存在優先問題。'on子句'中的未知列

的問題是在這條線 - group_membership_settings.group_id = groups.id

未知列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` 

回答

0

表(化名)groups不在範圍內自己的定義。

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

我不能說出你的意圖是什麼,但你可能還必須在內部查詢中加入groups

相關問題