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.

Example:

144,14,44,441,143,1454

Suppose you have stored such type of data in mysql column and you want to find out 14 from this string.


Solution:

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.

Categories: web development codeigniter mysql

Trending Courses

CodeIgniter

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Advance Digital Marketing

Regular : 6 Months

Fastrack : 3 Months

Crash : 2 Months

React JS

Regular : 45 Days

Fastrack : 25 Days

Crash : 15 Days

Laravel

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Front End Developer

Regular : 6 Months

Fastrack : 4 Months

Crash : 2 Months

Request For Demo