title: How to check diference between two times in two MySQL tables?
body: <p>So I've got two tables:</p>
  
  <p>ic:</p>
  
  <pre><code>id | created
  ---|--------------------
  1  | 2016-03-31 16:20:03
  2  | 2016-03-31 16:25:18
  3  | 2016-03-31 16:28:09
  </code></pre>
  
  <p>status:</p>
  
  <pre><code>id | ic_id | timestamp
  ---|--------------------
  1  | 1     | 2016-03-31 16:20:03
  2  | 5     | 2016-03-31 16:25:18
  3  | 5     | 2016-03-31 16:28:09
  </code></pre>
  
  <p>I now want to find the average difference between the <code>ic.created</code> and the <code>status.timestamp</code> of the first corresponding record in the <code>status</code> table. I started out with this:</p>
  
  <pre><code>SELECT status.`timestamp` - informed_consent.created as difference
  FROM status
  WHERE status.`timestamp` &gt; '2017-06-19' 
  AND status.ic_id IN (
      SELECT informed_consent.id
      FROM informed_consent
      WHERE informed_consent.id = status.ic_id; 
  );
  </code></pre>
  
  <p>But I immediately get an <code>error in my mysql syntax</code>. I guess I can also use a left join, but I'm kinda lost here.</p>
  
  <p>Could anybody help me out in the right direction?</p>