/*table data contins like id,name,sal1,abc,12002,jaid,53003,union,10004,ravod.200i want output likeid , name, sal , max(sal), min(sal)1 ,abc ,1200 , null , null2 ,jaid ,5300 , yes , null3,union , 1000 , null ,null4,ravod ,200 ,null , yes*/create table #TestTable( id int, name varchar(10), salary int);goinsert into #TestTablevalues (1,'abc',1200), (2,'jaid',5300), (3,'union',1000), (4,'ravod',200);gowith MaxSalary as (select max(salary) MaxSalaryfrom #TestTable), MinSalary as (select min(salary) MinSalaryfrom #TestTable)select id, name, salary, case when MaxSalary is not null then 'Yes' end MaxSalary, case when MinSalary is not null then 'Yes' end MinSalaryfrom #TestTable tt left outer join MaxSalary ms1 on (tt.salary = ms1.MaxSalary) left outer join MinSalary ms2 on (tt.salary = ms2.MinSalary)godrop table #TestTable;go