title: MySQL - Limit a left join to the first date-time that occurs?
body: <p>Simplified table structure (the tables can't be merged at this time):</p>
  
  <p><strong>TableA:</strong></p>
  
  <pre><code>dts_received (datetime)
  dts_completed (datetime)
  task_a (varchar)
  </code></pre>
  
  <p><strong>TableB:</strong></p>
  
  <pre><code>dts_started (datetime)
  task_b (varchar)
  </code></pre>
  
  <p>What I would like to do is determine how long a task took to complete.  </p>
  
  <p>The join parameter would be something like </p>
  
  <pre><code>ON task_a = task_b AND dts_completed &lt; dts_started
  </code></pre>
  
  <p>The issue is that there may be multiple date-times that occur after the dts_completed.  </p>
  
  <p>How do I create a join that only returns the first tableB-datetime that occurs after the tableA-datetime?</p>