title: Use of GROUP BY twice in MySQL
body: <p>My table looks like this.</p>
  
  <pre><code>Location    Head    Id  IntTime
  1           AMD     1   1
  2           INTC    3   3
  3           AMD     2   2
  4           INTC    4   4
  5           AMD2    1   0
  6           ARMH    5   1
  7           ARMH    5   0
  8           ARMH    6   1
  9           AAPL    7   0
  10          AAPL    7   1
  </code></pre>
  
  <p>Location is the primary key. I need to GROUP BY Head and by Id and when I use GROUP BY, I need to keep the row with the smallest IntTime.</p>
  
  <p>After the first GROUP BY Id, I should get (I keep the smallest IntTime)</p>
  
  <pre><code>Location    Head    Id  IntTime
  2           INTC    3   3
  3           AMD     2   2
  4           INTC    4   4
  5           AMD2    1   0
  7           ARMH    5   0
  8           ARMH    6   1
  9           AAPL    7   0
  </code></pre>
  
  <p>After the second GROUP BY Head, I should get (I keep the smallest IntTime)</p>
  
  <pre><code>Location    Head    Id  IntTime
  2           INTC    3   3
  3           AMD     2   2
  5           AMD2    1   0
  7           ARMH    5   0
  9           AAPL    7   0
  </code></pre>
  
  <p>When I run the following command, I keep the smallest IntTime but the rows are not conserved.</p>
  
  <pre><code>SELECT Location, Head, Id, MIN(IntTime) FROM test 
  GROUP BY Id
  </code></pre>
  
  <p>Also, to run the second GROUP BY, I save this table and do again </p>
  
  <pre><code>SELECT Location, Head, Id, MIN(IntTime) FROM test2 
  GROUP BY Head
  </code></pre>
  
  <p>Is there a way to combine both commands?</p>
  
  <p>[Edit: clarification]
  The result should not contain two Head with the same value or two Id with the same value.
  When deleting those duplicates, the row with the smallest IntTime should be kept.</p>