Reputation: 2457
I have a string for example:
MatchString = "Renal and Dialysis Technologist and Technician"
I have a table that has a field called degree_name
As an example one of the degree names may be Dialysis Technician
.
I want to try to find degrees that contain a number of the words from the MatchString
above - maybe like 2 or 3 matches - is there an easy way to do this in mysql - if so what would the code look like?
Thanks!
Upvotes: 0
Views: 216
Reputation: 1107
I would use, WHERE LIKE 'Dialysis Technician%' that will give you a two word match. If you want three you would need to add additional words in the like. The % is looking for wildcards after the text so if you would like to see info from before Dialysis Technician if would need to look like this: WHERE LIKE '%Dialysis Technician'.
Upvotes: 0
Reputation: 14691
You will be getting good results with a full text search in boolean mode. First make sure your table is MyISAM, with a full text index on degree_name
. Then this query will return matches, and number of words matching your MatchString
:
SELECT degree_name,
MATCH (degree_name)
AGAINST ('Renal and Dialysis Technologist and Technician' IN BOOLEAN MODE) FROM degrees
WHERE MATCH (degree_name)
AGAINST ('Renal and Dialysis Technologist and Technician' IN BOOLEAN MODE)
Upvotes: 1