RLIKE : This operator in MySQL is used to performs a pattern match of a string expression against a pattern.
Syntax :
RLIKE pattern
Parameters : This method accepts one parameter as mentioned in syntax.
- pattern -The pattern which we want to match against an expression. Various pattern and their usage are described below.
Pattern | What the Pattern matches |
---|
* | Zero or more instances of string preceding it |
+ | One or more instances of strings preceding it |
. | Any single character |
? | Match zero or one instances of the strings preceding it. |
^ | caret(^) matches Beginning of string |
$ | End of string |
[abc] | Any character listed between the square brackets |
[^abc] | Any character not listed between the square brackets |
[A-Z] | match any upper case letter. |
[a-z] | match any lower case letter |
[0-9] | match any digit from 0 through to 9. |
[[:<:]] | matches the beginning of words. |
[[:>:]] | matches the end of words. |
[:class:] | matches a character class i.e. [:alpha:] to match letters, [:space:] to match white space, [:punct:] is match punctuations and [:upper:] for upper class letters. |
p1|p2|p3 | Alternation; matches any of the patterns p1, p2, or p3 |
{n} | n instances of preceding element |
{m,n} | m through n instances of preceding element |
Example-1 : The following example finds the employees whose last name starts with the letter S.
CREATE TABLE Employee
(
Employee_id INT AUTO_INCREMENT,
First_name VARCHAR(100) NOT NULL,
Last_name VARCHAR(100) NOT NULL,
Joining_Date DATE NOT NULL,
PRIMARY KEY(Employee_id )
);
Inserting some data to the Employee table :
INSERT INTO Employee
(First_name ,Last_name , Joining_Date )
VALUES
('Sayantan', 'Majumdar', '2000-01-11'),
('Anushka', 'Samanta', '2002-11-10' ),
('Sayan', 'Sharma', '2005-06-11' ),
('Shayari', 'Das', '2008-01-21' ),
('Sayani', 'Jain', '2008-02-01' ),
('Tapan', 'Samanta', '2010-01-11' ),
('Deepak', 'Sharma', '2014-12-01' ),
('Ankana', 'Jana', '2018-08-17'),
('Shreya', 'Ghosh', '2020-09-10') ;
So, the Employee Table is as follows.
select * from Employee ;
Output :
Employee_id | First_name | Last_name | Joining_Date |
---|
1 | Sayantan | Majumdar | 2000-01-11 |
2 | Anushka | Samanta | 2002-11-10 |
3 | Sayan | Sharma | 2005-06-11 |
4 | Shayari | Das | 2008-01-21 |
5 | Sayani | Jain | 2008-02-01 |
6 | Tapan | Samanta | 2010-01-11 |
7 | Deepak | Sharma | 2014-12-01 |
8 | Ankana | Jana | 2018-08-17 |
9 | Shreya | Ghosh | 2020-09-10 |
Now, we are going to check those employees whose last name starts with 'S'.
SELECT * FROM Employee
WHERE Last_name RLIKE '^S' ;
Output :
Employee_id | First_name | Last_name | Joining_Date |
---|
2 | Anushka | Samanta | 2002-11-10 |
3 | Sayan | Sharma | 2005-06-11 |
6 | Tapan | Samanta | 2010-01-11 |
7 | Deepak | Sharma | 2014-12-01 |
Example-2 : The following example finds the employees whose first name ends with the letter 'i'.
SELECT * FROM Employee
WHERE First_name RLIKE 'i$' ;
Output :
Employee_id | First_name | Last_name | Joining_Date |
---|
4 | Shayari | Das | 2008-01-21 |
5 | Sayani | Jain | 2008-02-01 |
Similar Reads
MySQL | Operator precedence Operator precedence specifies the order in which operators are evaluated when two or more operators with different precedence are adjacent in an expression. For example, 1+2/3 gives the different result as compared to (1+2)/3. Just like all other programming languages C, C++, Java etc. MySQL also ha
3 min read
CRUD Operations in MySQL As we know that we can use MySQL to use Structure Query Language to store the data in the form of RDBMS. SQL is the most popular language for adding, accessing, and managing content in a database. It is most noted for its quick processing, proven reliability, ease, and flexibility of use. The applic
3 min read
SQL AND Operator In SQL, the AND operator is an essential tool used to combine multiple conditions in a WHERE clause. This allows us to filter records based on multiple criteria, making our queries more specific and tailored to our needs. When used correctly, the AND operator can help us retrieve data that satisfies
5 min read
SQL NOT Operator The SQL NOT Operator is a logical operator used to negate or reverse the result of a condition in SQL queries. It is commonly used with the WHERE clause to filter records that do not meet a specified condition, helping you exclude certain values from your results.In this article, we will learn every
3 min read
Python MySQL - BETWEEN and IN Operator In this article, we are going to see the database operations BETWEEN and IN operators in MySQL using Python. Both of these operators are used with the WHERE query to check if an expression is within a range or in a list of values in SQL. We are going to use the below table to perform various operati
3 min read