title: SQL: How To Select Earliest Row
body: <p>I have a report that looks something like this:</p>
  
  <pre><code>CompanyA      Workflow27     June5
  CompanyA      Workflow27     June8
  CompanyA      Workflow27     June12
  CompanyB      Workflow13     Apr4
  CompanyB      Workflow13     Apr9
  CompanyB      Workflow20     Dec11
  CompanyB      Wofkflow20     Dec17
  </code></pre>
  
  <p>This is done with SQL (specifically, T-SQL version Server 2005):</p>
  
  <pre><code>SELECT company
     , workflow
     , date
  FROM workflowTable
  </code></pre>
  
  <p>I would like the report to show just the earliest dates for each workflow:</p>
  
  <pre><code>CompanyA      Workflow27     June5
  CompanyB      Workflow13     Apr4
  CompanyB      Workflow20     Dec11
  </code></pre>
  
  <p>Any ideas? I can't figure this out. I've tried using a nested select that returns the earliest tray date, and then setting that in the WHERE clause. This works great if there were only one company:</p>
  
  <pre><code>SELECT company
     , workflow
     , date
  FROM workflowTable
  WHERE date = (SELECT TOP 1 date
                FROM workflowTable
                ORDER BY date)
  </code></pre>
  
  <p>but this obviously won't work if there is more than one company in that table. Any help is appreciated!</p>