title: SQL Server group by clause and display all columns
body: <p>I have a table like this in <code>SQL Server</code>:</p>
  
  <pre><code>Id Name Grade Marks 
  1  ABC  8     150
  1  DEF  9     200
  2  GHI  10    180
  2  JKL  8     155
  3  MNO  9     150
  3  PQR  10    200     
  </code></pre>
  
  <p>I need to fetch highest <code>Marks</code> for each <code>Grade</code> along with <code>ID</code> and <code>Name</code>.
  The output should be like this:</p>
  
  <pre><code>Id  Name   Grade  Marks
  2   JKL    8      155
  1   DEF    9      200
  3   PQR    10     200 
  </code></pre>
  
  <p>This is what I tried</p>
  
  <p>select Id,Name,Grade,Marks from T1 
  where marks in (select max(marks) from T1 group by Grade)</p>
  
  <p>this was so immature try that i dint post it here and I didn't knew other ways to try it....</p>