Hi!I've written a query that looks like this:declare @listcol nvarchar(max)declare @query nvarchar(max)select @listcol = STUFF(( Select distinct '],[' + LTRIM(str(Subject_ID))from IUP ileft join Subjects Son i.Subject_ID=S.IDFOR XML PATH('')), 1, 2, '') + ']'set @query ='SELECT * FROM ( SELECT Elev_ID, Subject_ID, Teacher_ID FROM IUP) myTemp PIVOT (count(Teacher_ID) FOR Subject_ID IN (' +@listcol+')) AS pvtorder by Elev_ID'execute (@query)As you can see i use count(Teacher_ID) for the Pivot.But i would like to get the first found Teacher_ID for each Subject_ID and Elev_ID instead of just getting the count. I am pretty noob so please help :)