title: mysql select subquery in yii2
body: <p>Hi i'd like to let this</p>
  
  <pre><code>ID | Forename | Surname | Created
  ---------------------------------
   1 | Tom      | Smith   | 2008-01-01
   1 | Tom      | Windsor | 2008-02-01
   2 | Anne     | Thorn   | 2008-01-05
   2 | Anne     | Baker   | 2008-03-01
   3 | Bill     | Sykes   | 2008-01-20
  </code></pre>
  
  <p>becomes like this</p>
  
  <pre><code>ID | Forename | Surname | Created
  ---------------------------------
   1 | Tom      | Windsor | 2008-02-01
   2 | Anne     | Baker   | 2008-03-01
   3 | Bill     | Sykes   | 2008-01-20
  </code></pre>
  
  <p>so I make a mysql query : </p>
  
  <pre><code>SELECT 
    * 
  FROM tableA as A 
  WHERE created = (
      SELECT 
          MAX(created) 
      FROM tableA GROUP BY id having id=A.id
  );
  </code></pre>
  
  <p>and it works in mysql as well , I can get what i want.</p>
  
  <p>but i dont know how to write this in yii2 active </p>
  
  <p>I have tried :</p>
  
  <pre><code> $query = (new \yii\db\Query())
                          -&gt;select(['A.*'])
                          -&gt;from('tableA AS A')
                          -&gt;where('created = (SELECT MAX(created) from tableA GROUP BY id having id=A.id');
  
  $command = $query-&gt;createCommand();
  $data = $command-&gt;queryAll();
  </code></pre>
  
  <p>but it didn't work.</p>
  
  <p>thanks.</p>