• Hi Guys Finally i got solution:-)

    SELECT ISNULL(s12.StudentID, s13.StudentID) AS StudentID,

    ISNULL(s12.majorsubject, s13.majorsubject) AS majorsubject,

    s12.minorsubject, s13.optional

    FROM

    (

    SELECT s1.StudentID, s1.majorsubject, s2.minorsubject,

    ROW_NUMBER() OVER (PARTITION BY s1.StudentID, s1.majorsubject ORDER BY s1.StudentID, s1.majorsubject) AS rnMS

    FROM #sem01 s1

    LEFT JOIN #sem02 s2 ON s1.StudentID = s2.StudentID

    ) s12

    FULL JOIN

    (

    SELECT s1.StudentID, s1.majorsubject, s3.optional,

    ROW_NUMBER() OVER (PARTITION BY s3.StudentID, s1.majorsubject ORDER BY s3.StudentID, s1.majorsubject) AS rnMS

    FROM #sem01 s1

    LEFT JOIN #sem03 s3 ON s1.StudentID = s3.StudentID

    ) s13 ON

    s12.StudentID = s13.StudentID and s12.majorsubject = s13.majorsubject

    and s12.rnMS = s13.rnMS

    ORDER BY StudentID