Если вы используете Oracle 11, вы можете попробовать это:
select t3.id, t3.terms||','||t4.terms terms from
(
select t1.id, listagg(t1.terms,',') within group (order by t1.terms) terms
from terms_table t1 join tfidf_table t2 on t1.id=t2.id
where instr(t2.terms,t1.terms)=0
group by t1.id )
t3 right outer join tfidf_table t4 on t3.id=t4.id
В Oracle 10 вы можете попробовать
select t3.id, t3.terms||','||t4.terms terms from
(
select t1.id, wm_concat(t1.terms) terms
from terms_table t1 join tfidf_table t2 on t1.id=t2.id
where instr(t2.terms,t1.terms)=0
group by t1.id )
t3 right outer join tfidf_table t4 on t3.id=t4.id