Was wird hier eigentlich gemacht?
Zuerst brauchen wir ein bestimmtes Wort (bzw. eine Liste der IDs zu Wörtern, die dem Suchbegriff ähneln):
select wordid from ftiword where (w.word like {s gesuchteswort%})
Zu diesem Ergebnis möchten wir alle DocID:
SQL-Code:
select id.docid from ftiwid id where exists (
select 1 from ftiword w where (w.word like {s gesuchteswort%}) and id.wordid = w.wordid
)
Zu diesem Ergebnis benötigen wir nun alle Dokumente:
SQL-Code:
select * from document a where exists
(
select 1 from ftiwid id where exists
(
select 1 from ftiword w where (w.word like {s gesuchteswort%}) and id.wordid = w.wordid
) and id.docid = a.docid
)
Keine Ahnung, ob
MSSQL mit so'ner Syntax zurecht kommt.
Warum wird im zweiten
SQL nach einer konkreten ID gesucht und zusätzlich noch in einer Liste von IDs?
Hier würd' ich's dann mit 'nem Union versuchen:
SQL-Code:
select * from document where docid = 200001
union
select * from document a where exists
(
select 1 from ftiwid id where exists
(
select 1 from ftiword w where (w.word like {s gesuchteswort%}) and id.wordid = w.wordid
) and id.docid = a.docid
)
Wenn das nicht geht:
SQL-Code:
select * from document where docid = 200001
union
SELECT * FROM document
WHERE docid IN (SELECT id.docid FROM ftiwid id INNER JOIN ftiword w ON id.wordid = w.wordid WHERE (w.word LIKE {s gesuchteswort%}) )