title: postgresql Select all rows which have max value in one column
body: <p>I'm new to postgresql, I have a table T like this in postgresql:</p>
  <pre><code>C1 C2 C3 C4 ID
  </code></pre>
  <p>C1,C2, C4 are int.<br />
  C3 is a char
  C4 is essentially the version number. and can be anything between 1-N.<br />
  ( For example, after one set of insert events the values in table are updated.)
  ID is a char.</p>
  <p>Question:<br />
  For a given value of ID, I want to select all rows that have highest C4 associated with them.  For example there could be N versions in the table,
  I want all results corresponding to the version N.</p>
  <p>I tried,</p>
  <p><code>select C1,C2,C3, max(C4) from T where ID = 'something';</code></p>
  <p>but it gives me error.</p>
  <p>Please advise.</p>