You can try the following:
SELECT LEAST(a,b) a, GREATEST(a,b) b
FROM t
GROUP BY LEAST(a,b), GREATEST(a,b)
With the following test pattern t:
CREATE TABLE t ( a VARCHAR(1), b VARCHAR(1) );
INSERT INTO t VALUES ('w','x'),('x','w'),('y','z'),('z','y');
it returns:
w x
y z
Using LEASTand GREATEST, also be sure to w xreturn instead x w.
source
share