is this u want check this once declare @tab table(code int,detail varchar(32)) insert into @tab select 4,'victor' insert into @tab select 4,'18' insert into @tab select 5,'macy' insert into @tab select 5,'24'
select code, max(case when code = 4 then detail when code = 5 then detail end) as name, min(case when code = 4 then detail when code = 5 then detail end) as age from @tab group by code