title: missing FROM-clause entry for table when using string_agg
body: <p>I have this query to try to search for the course that fulfills 3 requirements.</p>
  
  <pre><code>select
      course.id,
      course.title,
      course.number,
      string_agg(requirement.description,'; ' order by requirement.description) 
  from course
  join
  (
      select course.id, course.title, course.number
      from requirement join course_requirement 
          on (requirement.id=course_requirement.requirement)
      join course on (course.id=course_requirement.course) 
      where requirement.description='Human Behavior'
  ) as c1
      on (c1.id=course.id)
  join
  (
      select course.id, course.title, course.number 
      from requirement
      join course_requirement
          on (requirement.id=course_requirement.requirement)
      join course
          on (course.id=course_requirement.course) 
      where requirement.description='Intercultural'
  ) as c2
      on (c1.id=c2.id)
  join
  (
      select course.id, course.title, course.number 
      from requirement
      join course_requirement
          on (requirement.id=course_requirement.requirement)
      join course
          on (course.id=course_requirement.course) 
      where requirement.description='Religion'
  ) as c3
      on (c1.id=c3.id)
  group by course.id, course.title, course.number;
  </code></pre>
  
  <p>However, I receive this message: ERROR:  missing FROM-clause entry for table "requirement"
  LINE 1: ...course.id, course.title, course.number,string_agg(requiremen...
  Can you tell me where did I get the query wrong?</p>
  
  <p>Thank you so much!</p>