Here are a couple of ways (PS it's easier if you post your data in a consumable format):--Sample DataDECLARE @Foo TABLE (Plant CHAR(1), Plant2 CHAR(1))INSERT @FooVALUES('a', 'b'),('b', 'a'),('a', 'd'),('s', 'y'),('a', 'b')-- Using MIN/MAX with VALUES clauseSELECT P1 AS Plant, P2 AS Plant2, COUNT(*) AS [Sum]FROM ( SELECT (SELECT MIN(P) FROM (VALUES (Plant), (Plant2)) AS Foo(P)) AS P1, (SELECT MAX(P) FROM (VALUES (Plant), (Plant2)) AS Foo(P)) AS P2 FROM @Foo AS F ) AS TGROUP BY P1, P2--Using Case expressionSELECT CASE WHEN Plant <= Plant2 THEN Plant ELSE Plant2 END AS Plant, CASE WHEN Plant > Plant2 THEN Plant ELSE Plant2 END AS Plant2, COUNT(*) AS [Sum]FROM @FooGROUP BY CASE WHEN Plant <= Plant2 THEN Plant ELSE Plant2 END, CASE WHEN Plant > Plant2 THEN Plant ELSE Plant2 END