Не совсем уверен, что понимаю, и я надеюсь, что есть лучший способ сделать хорошую часть тегов, но:
select id from topic
inner join topic_tags tta on topic.id=tta.topicFk and tta.tagFk=a
inner join topic_tags ttb on topic.id=ttb.topicFk and ttb.tagFk=b
inner join topic_tags ttc on topic.id=ttc.topicFk and ttc.tagFk=c
left join topic_tags tt on topic.id=tt.topicFk and tt.tagFk in (d,e,f)
where tt.topicFk is null;
Обновление: примерно так:
select id from topic
left join topic_tags tt on topic.id=tt.topicFk and tt.tagFk in (d,e,f)
where tt.topicFk is null and
3=(select count(*) from topic_tags where topicFk=topic.id and tagFk in (a,b,c));
Я вижу один ответ, предполагая, что a, b, c, d, e, f являются именами, а не идентификаторами. Если так, то это:
select id from topic
left join topic_tags tt on topic.id=tt.topicFk
inner join tags on tt.tagFk=tags.id and tags.name in (d,e,f)
where tt.topicFk is null and
3=(select count(*) from tags inner join topic_tags on tags.id=topic_tags.tagFk and topic_tags.topicFk=topic.id where tags.name in (a,b,c));