select id from ( select a.id from ( select 1 as id from dua union all select 2 as id from dua ) a join (select 4 as id from dua) f on a.id =f.id union all select b.id from ( select 1 as id from dua union all select 2 as id from dua ) b join (select 3 as id from dua) e on b.id =e.id ) c