1

What we're trying to do is create a text search for an 'Any Word' type of match. The table is setup for example like this:

ID | Keyword
-------------
1  | alpha, beta, charlie
2  | bravo, delta, echo
3  | alpha, delta, foxtrot

The query that we've attempted so far is like this:

SELECT keyword FROM KeywordTest
       WHERE keyword 
 IN (select Value FRom split('alpha, beta, charlie',','))

What we thought would happen is that we would get two results back, one for ID 1, and one for ID 3. But that's not what happens we're only getting ID 1.

What am I doing wrong, and how could I tweak this query to bring back a match for 'Any Words' which are passed in as parameters.

Thanks!

2 Answers 2

3

The problem is in the where, because keyward in not IN the select, the keyword is LIKE the select. You can try with a INNER JOIN:

SELECT  keyword 
FROM    KeywordTest a inner join
        split('alpha, beta, charlie',',') b on a.keyword like '%'+Value+'%'
1
  • This is almost exactly what we were looking for. On our test data we found that we had hits bring back results for 'alpha, and 'charlie'. Tossing a distinct on the query worked for our solution. Thanks!.
    – Chris
    Feb 8, 2011 at 21:09
1

I actually just tackled a very similar problem.

I believe what you want to take a look into is the LIKE keyword for SQL.

SELECT keyword FROM KeywordTest
       WHERE keyword LIKE %'alpha'%

Note, you may have to do some kind of split by delimiter to get your search results all into the LIKE query. (I can help with that if you need as well)

Also, keep in mind that the % is a wild card. Putting the % before and after the search criteria, will find that string within any context.

If we had put WHERE Keyword LIKE 'alpha'%, we would only find results which begin with alpha.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.