This might help:--Create Table MarkMasterCreate Table MarkMaster(mmId int, subject varchar(30) )--Insert Sample Data Into MarkMaster(Removed data for student abc just to make it a little easy) Insert Into MarkMasterSelect 1, 'Maths'Union ALLSelect 2, 'phyicis'Union ALLSelect 3, 'Chemistry'Union ALLSelect 4, 'Enlish'Union ALLSelect 5, 'CS'--Create Table MarkSubCreate Table MarkSub(mmId int, student varchar(10), marksObtained int )--Insert Sample Data Into MarkSubInsert Into MarkSubSelect 1, 'abc', 75Union ALLSelect 1, 'xyz', 70Union ALLSelect 1, 'pqr', 75Union ALLSelect 1, 'dfh', 90Union ALLSelect 2, 'xyz', 75Union ALLSelect 2, 'pqr', 80 Union ALLSelect 2, 'dfh', 45Union ALLSelect 3, 'xyz', 79Union ALLSelect 3, 'pqr', 87 Union ALLSelect 3, 'dfh', 95Union ALLSelect 4, 'xyz', 89Union ALLSelect 4, 'pqr', 47 Union ALLSelect 4, 'dfh', 65Union ALLSelect 5, 'abc', 85Union ALLSelect 5, 'xyz', 49Union ALLSelect 5, 'pqr', 57 Union ALLSelect 5, 'dfh', 65--Required QuerySelect p.student, p.Maths, p.phyicis, p.Chemistry, p.Enlish, CS From(Select a.student, b.subject, a.marksObtained From MarkSub As aJOIN MarkMaster as b ON a.mmId = b.mmId) As tPivot(MAX(marksObtained) For Subject In (Maths, phyicis, Chemistry, Enlish, CS)) as p
N 28° 33' 11.93148"E 77° 14' 33.66384"