How to search for exact matched word using MySql Query

356

Today In this post We’ll discuss about How to search for exact matched word using MySql Query, Yesterday I face issue which i am going to tell you, I need to fetch data from database with exact matched keyword input by user, You must have face same situation like me and you may used Like query in mysql but it’ll not return what you are looking for,

Suppose you want to fetch data which contain “able” keyword, if you’ll use normal Like query it’ll also fetch data like “disable” etc, So for getting exact matched keyword you can use REGEXP in your mysql query. See following example query.

CompanyName
Company1
Company11
Company111
Company112

MySQL query for getting matched word.

SELECT * FROM companies WHERE CompanyName REGEXP "[[:<:]]Company1[[:>:]]";

Or you can also use RLIKE

SELECT * FROM companies WHERE CompanyName RLIKE "[[:<:]]Company1[[:>:]]";