title: SQL difference between two rows having the same id
body: <p>I would like to know how to take the difference in value (Val) for two rows having the same ID and return that from a SQL query. The difficulty here is that I was the difference between the second row and the first one, and each ID only has two rows.</p>
  
  <p>I am using SQLite 3.8.6.</p>
  
  <p>Here is what my table looks like:</p>
  
  <pre><code>ID   Val   TimeStamp
  +---+----+---------------------+
  | 2 |  7 | 2015-05-09 12:54:39 |
  | 2 |  2 | 2015-05-09 14:48:30 |
  | 3 | 16 | 2015-05-09 13:19:57 |
  | 3 | 20 | 2015-05-09 15:01:09 |
  +---+----+---------------------+ 
  </code></pre>
  
  <p>I want to end up with:</p>
  
  <pre><code>ID   Val   
  +---+----+
  | 2 |  -5|
  | 3 |  4 |
  +---+----+
  </code></pre>