title: MySQL Limit Rows / Group By
body: <p>I have searched a lot of different posts about this and i didn't find something that works for me.</p>
  
  <p>This <a href="https://stackoverflow.com/questions/2129693/using-limit-within-group-by-to-get-n-results-per-group">Using LIMIT within GROUP BY to get N results per group?</a> and <a href="http://www.sqlines.com/mysql/how-to/get_top_n_each_group" rel="nofollow noreferrer">http://www.sqlines.com/mysql/how-to/get_top_n_each_group</a> didn't  work for me.</p>
  
  <p>I have a simple MySQL Table with the following columns</p>
  
  <pre><code>id , package, user_id, date
  </code></pre>
  
  <p>I want to perform a query in which i will get </p>
  
  <blockquote>
    <p>X Rows / user_id WHERE date > Number Order By date ASC</p>
  </blockquote>
  
  <p>In short, we want to perform a <code>Group By user_id</code> with <code>LIMIT of X rows / group</code> but have in mind the statement using the <code>date column</code></p>
  
  <p><strong>Example Full Table</strong>:</p>
  
  <pre><code>id , package, user_id, date
  1,  full, 1 , 1447003159
  2,  full, 1 , 1447003055
  3,  full, 1 , 1447002022
  4,  full, 1 , 1447001013
  5,  full, 1 , 1447000031
  6,  mid,  2 , 1447003159
  7,  mid,  2 , 1447003055
  8,  mid,  2 , 1447002022
  9,  mid,  2 , 1447001013
  10, mid,  2 , 1447000031
  </code></pre>
  
  <p>From the above table we want to Select only 2 rows / user_id but where date >= 1447000031 (But make <code>ORDER BY date ASC</code> first)</p>
  
  <p><strong>Expected Output</strong>:</p>
  
  <pre><code>4,  full, 1 , 1447001013
  3,  full, 1 , 1447002022
  9,  mid,  2 , 1447001013
  8,  mid,  2 , 1447002022
  </code></pre>