Friday 25 March 2016

How to Search for Exact word match FROM String using RLIKE



In this post we are going to learn on mysql query like how to search exact word match from string using RLIKE operator. If you have basic knowledge of mysql select query with where clause then you can easily understand what I want to teach you. When I working on one project then I have face one problem. The problem is that I have to search data from database where exact word is present in a given string. Exact word means suppose I want to search data where word 'Bla' present in given table string. That means I want to get that data in which column string has only 'Bla' word not 'Bla-123', '56-Bla', '12Bla56' etc. Only word 'Bla' present in a string.

So, Friends First I have used Where clause in Select query and try to get result but it not return any row. After this I have used wildcard LIKE operator and write query with using LIKE operator but it data with 'Bla' word but it also return that data with word like 'Bla-123', '56-Bla', '12Bla56'. So, Problem is not solve with LIKE operator.

 SELECT * FROM tbl_supplier WHERE sup_sub_industry_id LIKE '%4%';  



After this I have used RLIKE wildcards operator in my query. And I write this query.

 SELECT * FROM tbl_supplier where sup_sub_industry_id RLIKE '[[:<:]]4[[:>:]]';  

With help of this query I had get right result of data and I solve my problem. Here in this query "[[:<:]]" means substitute characters in the string BEGINING and "[[:>:]]" means substitute characters in the string END.

0 comments:

Post a Comment