title: Extreme value from every type in SQL
body: <p>I have SQL table with id_item, type, hour, minutes, id_client.
  I would like to display one record from each type, which was bought recently.
  I mean one record from each type where hour is the highest -&gt; if equal, then where minutes value is the highest.
  Is it possible? I tried some queries, but I can't figure out how to do this.
  I did this one:</p>
  <pre><code>SELECT type, MAX(hour) FROM shop AS a GROUP BY type ORDER BY type
  INNER JOIN (SELECT type, hour, minutes, id_client FROM shop AS b) ON a.type = b.type AND a.hour=b.hour
  </code></pre>
  <p>But there's an error &quot;syntax error at or near &quot;INNER&quot;.
  It also doesn't include checking minutes when hour is the same.</p>