I did this in SQL Server:
-- Setup test data: declare @table table ( col1 int, col2 int, col3 int ) insert into @table values (10, 20, 30) insert into @table values (40, 50, 60) insert into @table values (40, 50, 80) -- Here the query: select col1, col2, cast(min(col3) as varchar(10)) as col3 from @table group by col1, col2 having count(*) = 1 union all select col1, col2, 'xx' as col3 from @table group by col1, col2 having count(*) > 1
I assume this assumes that you do not have duplicate rows (where all fields are duplicates), otherwise you may have the wrong "xx".
source share