Unique triplets from pairs I have a table (mysql) in the following pairs' structure:

 home   | door
 table  | window
 door   | table
 window | home
 home   | table
 table  | door


I'm looking for the best solution (fast and logical, to run on large tables) to get all unique triplets i.e home is paired with door and also with window so that's a triplet, and it's cardinal order so window,door,home is not distinct from door,home,window etc. 

Wanted results:

home  | door   | window 
home  | door   | table 
home  | window | table 
table | door   | window
Not sure I understand the problem properly but here is a sketch that might get you going:

create table t 
( a char(10) not null
, b char(10) not null
,     primary key(a,b));

insert into t (a,b) 
values ('home','door')
      ,('table','window')
      ,('door','table')
      ,('window','home')
      ,('home','table')
      ,('table','door');


For simplicity, we define a view so that a &lt; b:

create view v as 
    select distinct least(a,b) as a, greatest(a,b) as b from t;


Now we know that we can chain v via a self-join. As ybercube pointed out:

select v1.a, v1.b, v2.b 
from v as v1 
join v as v2 
    on v1.b = v2.a;


won't work if we have the tuples (a,b),(a,c). So we add other connections as:

select distinct v1.a, v1.b, v2.b  
from v as v1  
join v as v2
  on v1.a in (v2.a, v2.b) or v1.b in (v2.a, v2.b)
where v1.a&lt;v1.b 
  and v1.b&lt;v2.b;


Needless to say, this will be very inefficient for large tables.