Find Exact Word from String in mysql
In this blog, you will learn how to find exact words from strings in a mysql database, sometimes we need to match an exact word from a string. In mysql developers mostly use like clause to match words but it does not match an exact word, so it gives the wrong output.
We will use regex, a regex called regular expression to match an exact word from a string. It will return the exact word, it is better than like clause it will give the correct output.
Suppose you have stored such type of data in mysql column and you want to find out 14 from this string.
SELECT * FROM `your-tablename` WHERE your-column-name REGEXP '[[:<:]]".14."[[:>:]]'
In the above query replace tablename with your tablename, replace your-column-name with your column name and between REGEXP we have written 14 , because we want to match 14 string. You can put the string which you want to match.