views:

80

answers:

1

Hi all,

I've poached a bit of example code from a site explaining how to do a simple text search. However, the example SQL statement isn't valid for my version (SQL Server 2008), so I was wondering if someone could help clarify what it should look like.

Here is the example pseudocode:

SELECT t1.id
FROM
  mytable t1, ..., mytable tN
ON
  t2.id = t1.id AND ... AND tN.id = t1.id
WHERE
  t1.text LIKE 'q1;%' AND ... AND tN.text LIKE 'qN;%'

Now I know there should be some joins in there but I can't seem to get the correct syntax.

You will probably need to look at the site for reference as to what is being done, so that is here:

http://www.alexandria.ucsb.edu/archive/2003/sql-text-search.html

It's the "contains-all-words" query example from about a third of the way down.

If someone can help with this I'll be very grateful as it seems to suit my needs exactly.

+1  A: 
SELECT t1.id
FROM
mytable1 t1
--SPECIFY JOINs HERE
inner join myTable2 t2 ON t1.id = t2.id
inner join myTable3 t3 ON t1.id = t3.id
--etc 
WHERE
   t1.text LIKE 'q1;%' AND ... AND tN.text LIKE 'qN;%'
pjp
This is essentially the same as Raj's answer. Note that using INNER JOIN expects that t1.id is found as the id in all of the other t(n) tables. If this is not the case then you'll need to use a LEFT OUTER JOIN to include all items from t1 and only those that match from the other t(n) tables.
pjp
Thanks - that is almost what I had converted it to myself, was just getting a bit confused. Much appreciated.
Dave

related questions