Scotsman has asked for the wisdom of the Perl Monks concerning the following question:
Hi there
I'm looking for help with an SQL problem. I have 2 tables which contain 'keywords' (Keyword1-6 in each table). I'm trying to find a way to efficiently find all records in one table that match one or more of the keywords extracted from a record in the other table, and allow me to sort results in order of highest match.
Sorry if its tough to follow. So for example, in one table i have some records like this:
Record 1:
Keyword1 "Architect"
keyword2 "Major projects"
Keyword3 "London"
Record 2:
Keyword1 "Architect"
Keyword2 "Small projects"
Keyword3 "Sydney"
etc.and in the other table I have a record which I want to search with
Keyword1 "Architect"
Keyword2 "Hong Kong"
Keyword3 "Small"
say.I can put those into a string, thus "Architect Sydney Small", and search through the first table to find all full/partial matches.
Since both records in the first table match the search at least partially, I want to return both records from the second table, sorted in order of the best match, eg.
Record2 - 3 keyword matches (one partial)
Record1 - 2 matches
Note the order of Keywords may be different in both tables as shown above. I'm just trying to find anything that matches and sort into the best match order. Hope that's clear.
I've been trying a join but without much success. Any ideas on the best approach?
Thanks guys.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Finding best matches
by Corion (Patriarch) on Sep 12, 2013 at 09:37 UTC | |
|
Re: Finding best matches
by hdb (Monsignor) on Sep 12, 2013 at 09:40 UTC | |
|
Re: Finding best matches
by keszler (Priest) on Sep 12, 2013 at 13:11 UTC | |
|
Re: Finding best matches
by kcott (Archbishop) on Sep 12, 2013 at 23:36 UTC |