Click here to Skip to main content
15,915,600 members
Home / Discussions / Database
   

Database

 
GeneralDataset Diff - Pin
jmwalke120-May-03 14:22
jmwalke120-May-03 14:22 
GeneralParamaterized Queries Pin
David Salter20-May-03 11:22
David Salter20-May-03 11:22 
GeneralADO help pls Pin
BlackRider20-May-03 5:16
BlackRider20-May-03 5:16 
GeneralAttn: sql gurus, help! Pin
Member 9619-May-03 12:38
Member 9619-May-03 12:38 
GeneralRe: Attn: sql gurus, help! Pin
andyharman19-May-03 13:58
professionalandyharman19-May-03 13:58 
GeneralRe: Attn: sql gurus, help! Pin
Member 9619-May-03 16:41
Member 9619-May-03 16:41 
GeneralRe: Attn: sql gurus, help! Pin
Member 9620-May-03 5:15
Member 9620-May-03 5:15 
GeneralRe: Attn: sql gurus, help! Pin
Anonymous25-May-03 14:26
Anonymous25-May-03 14:26 

Select DocId, Count(Distinct WordKey) From srchkey
Where WordKey In (Select WordKey From srchdict
Where WordText In ("list", "of", "words"))
Group By DocId
Having Count(Distinct WordKey) = 3


Using the IN keyword is generally pretty slow. Using IN with a SELECT sub-query is even slower. It's generally a good idea to start out (i.e. prototype) like this, to see if you've got the right basic idea, but you'll want to rewrite the query to use JOINs for production use. As the poster noted, this will require a temporary table containing the search terms.

tblDocuments ( id INT PRIMARY KEY, document TEXT )
tblKeywords ( id INT PRIMARY KEY, keyword NVARCHAR(50) )
tblStatistics ( keyword_id INT, document_id INT, frequency INT )
with PRIMARY KEY as combination of keyword_id and document_id
tblCriteria ( term NVARCHAR(50) ) <--- a temporary table containing the search terms

SELECT D.id, count(D.id)
FROM tblCriteria C
LEFT OUTER JOIN tblKeywords K ON K.keyword = C.term
RIGHT OUTER JOIN tblStatistics S ON S.keyword_id = K.id
LEFT OUTER JOIN tblDocuments D ON D.id = S.document_id
GROUP BY D.id
HAVING count(D.id) = count(C.term)

This is what you should start out with. You probably want to rank the results based on the combined frequency of terms (from the tblStatistics.frequency column).

Make sure to have good indeces on the tblKeywords table, actually on all the tables. If the data remains fairly constant, you should not have a problem with indeces.
GeneralMostly working stored procedure revised Pin
Mike Osbahr19-May-03 11:09
Mike Osbahr19-May-03 11:09 
GeneralClarification Pin
Mike Osbahr19-May-03 16:18
Mike Osbahr19-May-03 16:18 
GeneralDesign Question Pin
Mark Sanders18-May-03 9:33
Mark Sanders18-May-03 9:33 
GeneralRe: Design Question Pin
Jeremy Oldham19-May-03 3:42
Jeremy Oldham19-May-03 3:42 
Generalcollation , locale ID Pin
Hesham Amin16-May-03 5:36
Hesham Amin16-May-03 5:36 
GeneralGot it !! Pin
Hesham Amin16-May-03 21:23
Hesham Amin16-May-03 21:23 
GeneralInstalling MSDE question Pin
DxSolo16-May-03 5:02
DxSolo16-May-03 5:02 
GeneralRe: Installing MSDE question Pin
Wayne Phipps16-May-03 21:58
Wayne Phipps16-May-03 21:58 
QuestionDatabase create code problem with deskop sql 2000? Pin
Bart-Man15-May-03 10:31
Bart-Man15-May-03 10:31 
AnswerSOLUTION Pin
Bart-Man16-May-03 5:29
Bart-Man16-May-03 5:29 
GeneralFetching Text ado.net(OLEDB) from sysbase DB Pin
vnagaraj14-May-03 8:26
vnagaraj14-May-03 8:26 
QuestionSSN Format Query? Pin
Steven Behnke14-May-03 7:03
Steven Behnke14-May-03 7:03 
Questionindependent Recordset ? Pin
AndreasSaurwein14-May-03 5:19
sussAndreasSaurwein14-May-03 5:19 
AnswerRe: independent Recordset ? Pin
Andreas Saurwein15-May-03 1:42
Andreas Saurwein15-May-03 1:42 
GeneralDate functions Pin
Anonymous13-May-03 10:59
Anonymous13-May-03 10:59 
GeneralRe: Date functions Pin
Anonymous13-May-03 21:04
Anonymous13-May-03 21:04 
GeneralBacking up and restoring tables in SQL Server Pin
prinju philip12-May-03 20:58
sussprinju philip12-May-03 20:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.