Hi,
Try this query
SELECT SU.SubjectCode, SU.SubjectName,
CASE WHEN SU.SubjectCode='Subject1'
THEN (SELECT Distinct Subject1 FROM StudentGrade)
CASE WHEN SU.SubjectCode='Subject2'
THEN (SELECT Distinct Subject2 FROM StudentGrade)
CASE WHEN SU.SubjectCode='Subject3'
THEN (SELECT Distinct Subject3 FROM StudentGrade)
CASE WHEN SU.SubjectCode='Subject4'
THEN (SELECT Distinct Subject4 FROM StudentGrade)
ELSE NULL END AS 'Grade',
CASE WHEN Grade IN ('a','b') THEN 'Pass' ELSE 'Fail' END AS 'Result'
FROM Subject SU
Hope it works