create table #结果表 (id int)while (select count(*) from #结果表)<=10
  insert #结果表 select top 1 * from a where id not in (select id from #结果表 union all select t1id from b where t2id in (select id from #结果表) union all select t2id from b where t1id in (select id from #结果表)) order by newid()