title: Min of Grouping with Max
body: <p>I have a question regarding how to write a query of the following table:</p>
  
  <pre><code>File#        Test#        Phase#      
  ----------  ----------  ----------
  A           1           1         
  A           1           2         
  A           2           1     
  </code></pre>
  
  <p>which result should be as the following :</p>
  
  <pre><code>  File#        Test#        Phase#      
  ----------  ----------  ----------
    A             2           1     
  </code></pre>
  
  <p>What I would like to do is to have the <strong>test</strong> with the **lowest phases*!!</p>
  
  <p>Further explanations: </p>
  
  <p>Test 1 has two phases( Phase 1, Phase 2)</p>
  
  <p>Test 2 has only one phase ( Phase) </p>
  
  <p>Thus , for file A , the test with lowest number of phases is <strong>test 2</strong></p>
  
  <p>My trails:</p>
  
  <p>I was able to take the max value of phases for each test by the following query:</p>
  
  <pre><code>Select File, Test , Max(Phase) as MaxPhases
  From table
  Group by File, Test
  </code></pre>
  
  <p>Then , I thought of taking the minimum values of the result, which It should be like this :</p>
  
  <pre><code>Select Min (t1.MaxPhases ) 
  From ( Select File, Test , Max(Phase) as MaxPhases
      From table
      Group by File, Test) t1
  </code></pre>
  
  <p>but I could not add the other info of File#, Test#... I was able to take the minimum only..</p>