Thursday, 18 October 2012

SQL Query: Select from Two separate Query


SELECT S.STYR_Student_ID, S.StartDate, E.EndDate, S.FirstYear, E.LastYear

From

(SELECT                STYR_Student_ID, MIN(STYR_Enrolled_On) AS StartDate, MIN(STYR_Year) AS FirstYear
FROM                   NG.dbo.STYRstudentYR
GROUP BY           STYR_Student_ID) AS S

INNER JOIN

(SELECT                STYR_Student_ID, MAX(STYR_Drop_Out_Date) AS EndDate, MAX(STYR_Year) AS LastYear
FROM                   NG.dbo.STYRstudentYR
GROUP BY           STYR_Student_ID) AS E

ON S.STYR_Student_ID = E.STYR_Student_ID

ORDER BY S.STYR_Student_ID

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home