Reputation: 1181
MySQL like clause lets wildcard searches like '%keyword%'
where keyword is sandwiched within the column value.
For pattern matching where the keyword contains a part of the column value and when %keyword%
will not work, we can use INSTR
function to do the search.
Example:
Column="Apple"
$keyword = "An Apple a day"
Here, we cannot do Column like '%$keyword%'
to make a match but (INSTR('$Keyword', Column)>0
would do the match.
What alternatives (regex?, fulltext search?, lucene?) do we have other than INSTR for pattern-matching such cases (examples?) ?
Update:
Column = "Golden Apple"
$keyword = "An Apple a day"
Even for samples like this, I would like to be able to match the $keyword with column as they have a common term "Apple".
Upvotes: 2
Views: 5234
Reputation: 53840
Also consider SOUNDEX and Natural Language (using full text searches and relevance) searches.
Upvotes: 0
Reputation: 115550
In this case, you can still use LIKE
:
'%$keyword%' LIKE CONCAT('%', Column, '%')
Or regular expression:
'%$keyword%' REGEXP Column
Upvotes: 1
Reputation: 2640
I don't understand clearly what exactly you want to do, but try this link to find the help about pattern matching in mysql
Are you writing a procedure,a trigger, or simply a select?
Upvotes: 1