create table #temp(col1 nvarchar(10), col2 nvarchar(10) , col3 int) --测试数据
insert into #temp
select 'A ' , 'a', 1 union
select 'A' , 'a ', 2 union
select 'B ' , 'a ' , 3 union
select 'B ' , 'a' , 4 union
select 'C ' ,'a' , 5 union
select 'C ' , 'a' , 6 union
select 'A ' , ' b ' , 7 union
select 'A ' , ' b ' , 8 union
select 'A ' , 'A ' , 9 union
select 'A' , 'A ' , 10 union
select 'B' , 'B ' , 11 union
select 'D', 'c ' ,12 union
select 'D', 'c ' ,13 union
select 'E','c ' ,14 union
select 'E' ,'c ' , 15
select distinct * from #temp where LOWER(col1)=LOWER(col2)
union
select* from #temp where LOWER(col1)<>LOWER(col2) and col1=(select max(col1) from #temp where LOWER(col1)<>LOWER(col2))
drop table #temp --删除测试数据