![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Can we combine MySQL IN AND LIKE operators?
Yes, we can combine IN and LIKE operators in MySQL using LIKE and OR operator. Let us first create a table −
mysql> create table DemoTable -> ( -> SubjectTitle text -> ); Query OK, 0 rows affected (0.68 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Introduction To MySQL'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Java in Depth'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Coding with Python'); Query OK, 1 row affected (0.54 sec) mysql> insert into DemoTable values('C++ in Depth'); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+-----------------------+ | SubjectTitle | +-----------------------+ | Introduction To MySQL | | Java in Depth | | Coding with Python | | C++ in Depth | +-----------------------+ 4 rows in set (0.00 sec)
Following is the query to use LIKE and OR in a single MySQL query −
mysql> select *from DemoTable where SubjectTitle LIKE '%MySQL%' OR SubjectTitle LIKE'C++%';
Output
This will produce the following output −
+-----------------------+ | SubjectTitle | +-----------------------+ | Introduction To MySQL | | C++ in Depth | +-----------------------+ 2 rows in set (0.00 sec)
Advertisements