
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- Why in MySQL, we cannot use arithmetic operators like ‘=’, ‘
- How can we combine functions in MySQL?
- Can we use LIKE and OR together in MySql?
- Can we combine GridLayout and BorderLayout in Java?
- How can we combine ROW selection with COLUMN selection in MySQL?
- Can we use “LIKE concat()” in a MySQL query?
- Multiple LIKE Operators with ORDER BY in MySQL?
- Can we implement 'LIKE' and ‘IN’ in a single MySQL query?
- How can we use logical operators while creating MySQL views?
- Implement multiple LIKE operators in a single MySQL query
- How can we combine the values of two or more columns of MySQL table?
- Combine columns before matching it with LIKE in a single query in MySQL?
- How can we use a combination of logical operators while creating MySQL views?
- Can we use MySQL GROUP BY clause with multiple columns like MySQL DISTINCT clause is used?
- How can we combine multiple print statements per line in Python?

Advertisements