Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Temp table help 1

Status
Not open for further replies.

JohnnyLong

Programmer
Sep 27, 2002
97
GB
Hi,

I need some advice on the best way to solve the following:

SELECT CandidateID
FROM Notes
WHERE CONTAINS(subject, '"fish*"')
UNION
SELECT CandidateID
FROM Notes
WHERE CONTAINS(comments, '"fish*"')
UNION
SELECT CandidateID
FROM CandidatesNotes
WHERE CONTAINS(CandidateNotes, '"fish*"')

This gives me a result set of CandidateID's. I then need to Select the full candidate record from the Candidates table using the IDs. What's the best way of doing this? Is a temporary table the easist way?

Thanks for looking,

John
 
Code:
SELECT Candidates.*
       FROM Candidates
INNER JOIN Notes ON Candidates.CandidateID = Notes.CandidateID
WHERE CONTAINS(Notes.subject       , '"fish*"') OR
      CONTAINS(Notes.comments      , '"fish*"') OR
      CONTAINS(Notes.CandidateNotes, '"fish*"')
not tested


Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Thanks Borislav, but using joins with CONTAINS slows the search up too much. The Union query takes less than 2 seconds but the query with Joins takes 9 seconds.
 
Hmmm,
Code:
SELECT Candidates.*
       FROM Candidates
INNER JOIN (SELECT CandidateID
                   FROM Notes
                   WHERE CONTAINS(subject, '"fish*"')
            UNION
            SELECT CandidateID
                   FROM Notes
                   WHERE CONTAINS(comments, '"fish*"')
            UNION
            SELECT CandidateID
                   FROM CandidatesNotes
                   WHERE CONTAINS(CandidateNotes, '"fish*"'))
Test ON Candidates.CandidateID = Test.CandidateID

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Thanks alot Borislav, that's a 5 second search which is fine. You are a star.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top