title: How do you group by one column and retrieve a row with the minimum value of another column in T/SQL?
body: <p>So I know this is a pretty dumb question, however (as the rather lengthily title says) I would like to know how do the following:</p>
  
  <p>I have a table like this:</p>
  
  <pre><code>ID Foo Bar Blagh
  ----------------
  1  10  20  30
  2  10  5   1
  3  20  50  40
  4  20  75  12
  </code></pre>
  
  <p>I want to group by Foo, then pull out rows with minimum Bar, i.e. I want the following:</p>
  
  <pre><code>ID Foo Bar Blagh
  ----------------
  2  10  5   1
  3  20  50  40
  </code></pre>
  
  <p>I can't for the life of me work out the correct SQL to retrieve this. I want something like:</p>
  
  <pre><code>SELECT ID, Foo, Bar, Blagh
  FROM Table
  GROUP BY Foo
  HAVING(MIN(Bar))
  </code></pre>
  
  <p>However this clearly doesn't work as that is completely invalid HAVING syntax and ID, Foo, Bar and Blagh are not aggregated.</p>
  
  <p>What am I doing wrong?</p>