select s.name AS sName, m.name AS mName, l.name AS lName from `table` s,`table` m,`table` l where s.Id2 = m.Id1 and m.Id2 = l.Id1;
select name from `table` where Id1=1 union select name from `table` where Id2=1 union select name from `table` a inner join `table` b on a.Id2=b.Id1 where b.Id2=1;