below query returns expected result set. but i am thinking if i have different student status it many take lead in row number based on sorting order.fulltime will always take lead for a student even though they enrolled multiple ways.[code="other"]drop table #Student create table #Student(StudentId int not null,Studentstatus char(30),FeePaid varchar(10))insert into #Studentselect 1 , 'Intern', '$1000'union select 1 , 'Full time', '$2000'union select 2 , 'Full time', '$5000'drop table #tbl2create table #tbl2(StudentId int not null,StudentNm varchar(30),)insert into #tbl2select 1 ,'John'union select 2 ,'Rayn' ;WITH summary AS ( SELECT p.Studentstatus, p.StudentId , p.FeePaid, ROW_NUMBER() OVER(PARTITION BY p.Studentstatus ORDER BY p.StudentId DESC) AS rownum FROM #Student p join #tbl2 b on p.StudentId =b.StudentId)SELECT * FROM summary sWHERE s.rownum = 1[/code]
↧