title: How to GROUP BY and LIMIT N results from one field?
body: <p>In MySQL I have articles. Each article has category. I want get last N articles from each category ordered by date. How to do that in SQL? Also interested how to convert it to Yii2 Active Query.</p>
  
  <p>Example: 10 articles, 3 categories. Category <code>A</code> has 2 articles, category <code>B</code> has 3 articles, category <code>C</code> has 5 articles.</p>
  
  <p>With query like</p>
  
  <pre><code>SELECT *
  FROM articles
  GROUP BY 'category'
  LIMIT 2
  ORDER BY 'date'
  </code></pre>
  
  <p>I have to get 2 articles from <code>A</code>, 2 last articles from <code>B</code> and 2 last articles from <code>C</code></p>