title: Getting the First and Last Row Using ROW_NUMBER and PARTITION BY
body: <h1>Sample Input</h1>
  
  <pre><code>Name | Value | Timestamp
  -----|-------|-----------------
  One  | 1     | 2016-01-01 02:00
  Two  | 3     | 2016-01-01 03:00
  One  | 2     | 2016-01-02 02:00
  Two  | 4     | 2016-01-03 04:00
  </code></pre>
  
  <h1>Desired Output</h1>
  
  <pre><code>Name | Value | EarliestTimestamp | LatestTimestamp
  -----|-------|-------------------|-----------------
  One  | 2     | 2016-01-01 02:00  | 2016-01-02 02:00
  Two  | 4     | 2016-01-01 03:00  | 2016-01-03 04:00
  </code></pre>
  
  <h1>Attempted Query</h1>
  
  <p>I am trying to use <code>ROW_NUMBER()</code> and <code>PARTITION BY</code> to get the latest <code>Name</code> and <code>Value</code> but I would also like the earliest and latest <code>Timestamp</code> value:</p>
  
  <pre><code>SELECT
      t.Name,
      t.Value,
      t.????????? AS EarliestTimestamp,
      t.Timestamp AS LatestTimestamp
  FROM 
      (SELECT
          ROW_NUMBER() OVER (PARTITION BY Name ORDER BY TIMESTAMP DESC) AS RowNumber,
          Name,
          Value
          Timestamp) t
  WHERE t.RowNumber = 1
  </code></pre>