title: Show difference between two subqueries as additional column in MySQL query
body: <p>I have two tables, one with the main data and a second table with historical values. </p>
  
  <p>Table <code>stocks</code></p>
  
  <pre><code>+----------+-------+-----------+
  | stock_id | symbol| name      |    
  +----------+-------+-----------+    
  |        1 |  AAPL | Apple     |
  |        2 |  GOOG | Google    |
  |        3 |  MSFT | Microsoft |
  +----------+-------+-----------+
  </code></pre>
  
  <p>Table <code>prices</code></p>
  
  <pre><code>+----------+-------+---------------------+
  | stock_id | price | date                |    
  +----------+-------+---------------------+    
  |        1 |  0.05 | 2015-02-24 01:00:00 |
  |        2 |  2.20 | 2015-02-24 01:00:00 |
  |        1 |  0.50 | 2015-02-23 23:00:00 |
  |        2 |  1.90 | 2015-02-23 23:00:00 | 
  |        3 |  2.10 | 2015-02-23 23:00:00 |
  |        1 |  1.00 | 2015-02-23 19:00:00 |
  |        2 |  1.00 | 2015-02-23 19:00:00 | 
  +----------+-------+---------------------+
  </code></pre>
  
  <p>I need a query that returns:</p>
  
  <pre><code>+----------+-------+-----------+-------+
  | stock_id | symbol| name      | diff  |  
  +----------+-------+-----------+-------+    
  |        1 |  AAPL | Apple     | -0.45 |
  |        2 |  GOOG | Google    | 0.30  |
  |        3 |  MSFT | Microsoft | NULL  |
  +----------+-------+-----------+-------+
  </code></pre>
  
  <p>Where diff is the result of subtracting from the newest price of a stock the previous price.
  If one or less prices are present for a particular stock I should get NULL.</p>
  
  <p>I have the following queries that return the last price and the previous price but I don't know how to join everything</p>
  
  <pre><code>/* last */
  SELECT price 
  FROM prices
  WHERE stock_id = '1'
  ORDER BY date DESC 
  LIMIT 1
  
  /* previous */
  SELECT price 
  FROM prices
  WHERE stock_id = '1'
  ORDER BY date DESC 
  LIMIT 1,1
  </code></pre>
  
  <p>Using MySQL 5.5</p>