Question : T-SQL help table join

I have two tables:

T1.WORK_ID           T1.COMPANY_NAME            T1.work_LOCATION       
1            TEST_COMPANY1            TEST_COMPANY1_LOC1                   
2            TEST_COMPANY1            TEST_COMPANY1_LOC2                   
3            TEST_COMPANY1             TEST_COMPANY1_LOC3                   
4            TEST_COMPANY2             TEST_COMPANY2_LOC1                   
5            TEST_COMPANY2            TEST_COMPANY2_LOC2                   
6            TEST_COMPANY2            TEST_COMPANY2_LOC3                   


T2.WORK_ID      T2.start_date_time      T2.end_date_time
1            2010-01-02 8:00            2010-01-02 11:00      
2            2010-01-03 8:00            2010-01-03 10:00
3            2010-01-05 8:00            2010-01-05 11:30
4            2010-02-10 8:00            2010-02-10 09:30
5            2010-02-12 8:00            2010-02-12 12:00
6            2010-02-15 8:00            2010-02-15 10:30

The result I am looking for is:


COMPANY_NAME      START_DATE_TIME            END_DATE_TIME
TEST_COMPANY1   2010-01-02 8:00            2010-01-05 11:30
TEST_COMPANY2      2010-02-10 8:00            2010-02-15 10:30

note:
DISTINCT BY T1.COMPANY_NAME, EARLY_START_DATE_TIME, LAST_END_DATE_TIME
The T1 and T2 match by work_id

Thank you,

Answer : T-SQL help table join

SELECT T1.COMPANY_NAME, MIN(T2.start_date_time) AS START_DATE_TIME, MAX(T2.end_date_time) AS END_DATE_TIME
FROM T1 INNER JOIN
   T2 ON T1.WORK_ID = T2.WORK_ID
GROUP BY T1.COMPANY_NAME
Random Solutions  
 
programming4us programming4us