"N. Kavithashree" <[EMAIL PROTECTED]> wrote on 09/14/2005 
02:07:01 AM:

> 
> hello
> 
> i hv one query as explained below :
> 
> Table FIRST contains
> 
> This is
> What is this
> how
> whom
> color
> white
> 
> Table SECOND contains
> 
> WHOM
> THIS IS
> WHAT
> WHITE AND BLACK
> 
> i want the result as
> This is
> what is this
> what
> whom
> white
> WHITE AND BLACK
> 
> 
> i want a query which searches both table for exact match as well as 
partly
> match. Even if part of the string matches it should get displayed in the
> result.
> 
> thanks in advance
> kavitha
> 

First, you didn't exactly describe which table has the search terms in it 
and which table you were trying to find matches with. So I am forced to 
make a few guesses.

The problem I think you have is that I think you are trying to do matching 
that is neither pure equality, pattern matching, or full-text searching. I 
use as an example the case of trying to use "THIS IS" to return a match to 
"what is this" . There is no native SQL query you can compose that will 
perform that kind of permutation. There may be a way to somehow split your 
first term and match on its pieces. Or you could use the first term in a 
FT search but the problem with that approach is that the word "IS" has 
only two letters in it. That would mean that you would need to recompose 
your FT index to include words that small or smaller.

For full equality matches, you can use the = operator. For pattern 
matching you can use the LIKE or RLIKE operators. For fulltext searches 
use the MATCH...AGAINST operator. You can achieve a combination of those 
three results by UNION-ing the results together. That would be much more 
efficient (in terms of index usage) than trying to compute a single 
complex WHERE clause that "OR"-ed your three types of comparisons 
together.

If you are trying to simplify the problem, don't. To the best of your 
ability, please describe the actual problem. Show us the actual table 
definitions you want to use and a few rows of sample data and a partial 
example of what a successful query would look like and I guarantee that 
we, as a list, will either solve your problem or explain exactly what 
could not be solved using SQL.

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine

Reply via email to