1select d.StudentId, d.Name, d.Course, r1.result as Term1Result, r2.result as Term2Result
2from StudentDetails d
3left join StudentResults r1 on d.StudentId = r1.StudentId and r1.term = 1
4left join StudentResults r2 on d.StudentId = r2.StudentId and r2.term = 2
5