Friday, 21 November 2014

How to use RLIKE, LIKE in MySQL

RLike basically use as regular expression in string character, match the string and return result. If we talk about ‘LIKE’ uses as wildcard and ‘%’ substitute for unlimited amount of characters and finding the beginning and end of the character string.
If % use in starting then the result return for example:
Select * from Customer
Where customerID like ‘%5
The result will be:
customerIDName
5John
15smith
165carlos
Similarly, if % use in ending then the result return for example:
Select * from Customer
Where customerID like 5%’
customerIDName
51mular
52anna
567conny
Now, example of RLIKE:
The wildcards used with RLIKE operator are:
^ indicate BEGINING of the string.
$ indicate END of the string.
| means OR
Look for Customer names that have substring “John” or substring “Anna”:
SELECT CustomerID, CustomerName 
FROM Customers 
WHERE CustomerName RLIKE John|Anna’;
customerIDCustomerName
10smith John
13Anna jos

0 comments:

Post a Comment