title: Unique combination of multiple columns, order doesn't matter
body: <p>Suppose a table with 3 columns. each row represents a unique combination of each value:</p>
  <pre><code>a a a
  a a b
  a b a
  b b a
  b b c
  c c a
  ...
  </code></pre>
  <p>however, what I want is,</p>
  <pre><code>aab = baa = aba 
  cca = cac = acc
  ...
  </code></pre>
  <p>Finally, I want to get these values in a CSV format as a combination for each value like the image that I attached.</p>
  <p><img src="https://i.stack.imgur.com/e8yLy.png" alt="this" /></p>
  <p>Thanks for your help!</p>
  <p>Below is the query to generate my problem, please take a look!</p>
  <pre class="lang-sql prettyprint-override"><code>--=======================================
  --populate test data
  --=======================================
  drop table if exists #t0
  ;
  with 
  cte_tally as
  (
  select row_number() over (order by (select 1)) as n 
  from sys.all_columns
  )
  select 
    char(n) as alpha
  into #t0
  from 
    cte_tally
  where
    (n &gt; 64 and n &lt; 91) or
    (n &gt; 96 and n &lt; 123);
  
  drop table if exists #t1
  select distinct upper(alpha) alpha into #t1 from #t0
  
  drop table if exists #t2
  select
      a.alpha c1
  ,   b.alpha c2
  ,   c.alpha c3
  ,   row_number()over(order by (select 1)) row_num
  into #t2
  from #t1 a
  join #t1 b on 1=1
  join #t1 c on 1=1
  
  
  drop table if exists #t3
  select *
  into #t3
  from (
      select *
      from #t2
  ) p
  unpivot
      (cvalue for c in (c1,c2,c3)
  ) unpvt
  
  
  select
      row_num
  ,   c
  ,   cvalue
  from #t3
  order by 1,2
  
  --=======================================
  --these three rows should be treated equally
  --=======================================
  select *
  from #t2
  where concat(c1,c2,c3) in  ('ABA','AAB', 'BAA')
  
  --=======================================
  --what i've tried...
  --row count is actually correct, but the problem is that it ommits where there're any duplicate alphabet.
  --=======================================
  select 
      distinct
      stuff((
          select
              distinct
          '.' + cvalue
          from #t3 a
          where a.row_num = h.row_num
      for xml path('')
      ),1,1,'') as comb
  from #t3 h
  
  </code></pre>