select adminno,semid,(select top 1 (SubjectCode) from tabName as s1 where s1.adminno=s2.adminno and s1.semid=s2.semid order by SubjectCode) as SubName1 , (select top 1 (SubjectCode) from tabName as s1 where s1.adminno=s2.adminno and s1.semid=s2.semid order by SubjectCode desc) as SubName2 from tabName as s2