MySQL - Limit a left join to the first date-time that occurs?

Posted by John M on Stack Overflow See other posts from Stack Overflow or by John M
Published on 2010-06-10T18:07:51Z Indexed on 2010/06/10 18:12 UTC
Read the original article Hit count: 159

Filed under:
|
|
|
|

Simplified table structure (the tables can't be merged at this time):

TableA:

dts_received (datetime)
dts_completed (datetime)
task_a (varchar)

TableB:

dts_started (datetime)
task_b (varchar)

What I would like to do is determine how long a task took to complete.

The join parameter would be something like

ON task_a = task_b AND dts_completed < dts_started

The issue is that there may be multiple date-times that occur after the dts_completed.

How do I create a join that only returns the first tableB-datetime that occurs after the tableA-datetime?

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql