title: Get last values of n distinct fields
body: <p>I need some help with mysqli query. I have a table that contains fields user,card,action... like so</p>
  
  <pre><code>id   user   card   action   time
  1    1      1      1        5
  2    1      1      2        6
  3    1      1      3        7
  4    2      1      1        8
  </code></pre>
  
  <p>I need to get an array of <strong>10 last users</strong> with all of their actions, like so</p>
  
  <pre><code>array(
    2 =&gt; array(1),    
    1 =&gt; array(1,2,3)
  )
  </code></pre>
  
  <p>I tried using distinct but it only returns one action for each user and making multiple queries for it is probably not the best solution, i cant think of anything else to try. Maybe the combined query is needed but i cant figure out how to do it.</p>
  
  <p>Thank you!</p>
  
  <p>Okay, using the help i had i made my own query but for some reason, it fails to slelect the highest value of time, everything else is working. <a href="http://sqlfiddle.com/#!2/68751d/1" rel="nofollow">http://sqlfiddle.com/#!2/68751d/1</a></p>
  
  <pre><code>    $m = new_m();
      if ($s = $m -&gt; prepare("SELECT user, group_concat(action) as actions, time FROM cards_actions_data WHERE card=? GROUP BY user ORDER BY time DESC LIMIT 0, 10")) {
          $s -&gt; bind_param('i', $card);
          $s -&gt; execute();
          $s -&gt; bind_result($user,$actions,$time);
          while($s -&gt; fetch()){
              $users[$user]['time'] = $time; 
              $users[$user]['actions'] = $actions;
          }
          $s -&gt; close();
  
      }
      pre($users);
      pre($m);
      $m -&gt; close();
  
      return $users;
  </code></pre>