
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL Query to Display Records Using LIKE with Multiple Words
For this, use RLIKE and filter records as in the below syntax &Minus;
select * from yourTableName where yourColumnName rlike 'yourValue1|yourValue2';
Let us first create a table −
mysql> create table DemoTable1935 ( Subject varchar(20) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1935 values('MySQL'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1935 values('Python'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1935 values('MongoDB'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1935 values('SQL Server'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1935 values('PL SQL'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1935;
This will produce the following output −
+------------+ | Subject | +------------+ | MySQL | | Python | | MongoDB | | SQL Server | | PL SQL | +------------+ 5 rows in set (0.00 sec)
Here is the query to filter records:
mysql> select * from DemoTable1935 where Subject rlike 'SQL|Python';
This will produce the following output −
+------------+ | Subject | +------------+ | MySQL | | Python | | SQL Server | | PL SQL | +------------+ 4 rows in set (0.00 sec)
Advertisements