I have two tables with a description column in each one. The first table may have between 500,000 and 1,000,000 records, the second one may have between 1,000 and 10,000 records. I need to get the join of both tables based on the descriptions fields in each table but the problem is I should search the words in the descriptions fields in any order. For example "My house is red" should join with "Red is my house" or with "is red my house". So the words in the description field on the first table should be the same to the words in the description field on the second table without considering the order of those words.
I could create in both tables 7 or 8 varchar fields (the descriptions are never longer than 8 words) to store all the words from the descriptions fields of both tables if it could help.
How can I solve this having a good performance?
In table_b, word_1 has the first word of the description field for each record in this table, word_2 has the second word of the description field for each record in this table, and so on:
select a.*, b.*
from table_a a, table_b b
where a.descrip like b.word_1
and a.descrip like b.word_2
and a.descrip like b.word_3
and a.descrip like b.word_4
and a.descrip like b.word_5
and a.descrip like b.word_6