title: SELECT sub-query with WHERE condition in Yii2 find() / QueryBuilder
body: <p>I was able to find simple examples of sub-query building, but am unable to figure out nor find the solution when I need to include a WHERE condition. I am trying to simulate the following statement...</p>
  
  <pre><code>SELECT ParentTable.*, (SELECT MAX(ChildTable.NumberField) 
                         FROM ChildTable
                         WHERE ChildTable.FK_Id = ParentTable.Id)
  FROM ParentTable
  </code></pre>
  
  <p>Guess I'd need something like...</p>
  
  <pre><code>$query = ParentClass::find()
          -&gt;addSelect(
              ChildClass::find()
              -&gt;where('childTable.fk_id=parentTable.id')
              -&gt;max('childTable.field1')
          );
  </code></pre>
  
  <p>But it gives me an error: Column not found: 1054 Unknown column 'parentTable.id' in 'where clause'</p>
  
  <p>EDIT:
  Including actual class/table names...</p>
  
  <pre><code>$endQuery = UnitSchedule::find()
              -&gt;where('cm_courseschedule.id=cm_unitschedule.csch_id')
              -&gt;max('cm_unitschedule.slot');
  $query = CourseSchedule::find();
  $query-&gt;addSelect($endQuery);
  </code></pre>