Does this give you what you need? SELECT t1.TID, min(t1.StartTime) AS StartTime, MAX(t2.StartTime) AS ...
stackoverflow.com