DISTINCT column combination with permutations
This looks more like a stack overflow question yet Union will give a distinct combination.
SELECT concat("from",':',"to") as res From Table
UNION
SELECT concat("to",':',"from") From Table
You can also use least() and greatest() together with distinct
. That would preserve the individual values without the need to concatenate them.
select distinct least("from", "to"), greatest("from", "to")
from the_table;