- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Implement multiple LIKE operators in a single MySQL query
To implement multiple LIKE clauses, the syntax is as follows −
select * from yourTableName where yourColumnName1 LIKE ('%yourValue1%' or yourColumnName2 LIKE '%yourValue2%') or (yourColumnName3 LIKE '%yourValue3');
Let us first create a table −
mysql> create table DemoTable1534 -> ( -> ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ClientName varchar(20), -> ClientAge int, -> ClientCountryName varchar(20) -> ); Query OK, 0 rows affected (0.78 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1534(ClientName,ClientAge,ClientCountryName) values('Chris Brown',29,'AUS'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1534(ClientName,ClientAge,ClientCountryName) values('David Miller',49,'UK'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1534(ClientName,ClientAge,ClientCountryName) values('John Doe',43,'US'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1534(ClientName,ClientAge,ClientCountryName) values('Adam Smith',38,'US'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1534(ClientName,ClientAge,ClientCountryName) values('Carol Taylor',36,'UK'); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1534;
This will produce the following output −
+----------+--------------+-----------+-------------------+ | ClientId | ClientName | ClientAge | ClientCountryName | +----------+--------------+-----------+-------------------+ | 1 | Chris Brown | 29 | AUS | | 2 | David Miller | 49 | UK | | 3 | John Doe | 43 | US | | 4 | Adam Smith | 38 | US | | 5 | Carol Taylor | 36 | UK | +----------+--------------+-----------+-------------------+ 5 rows in set (0.00 sec)
Following is the query for multiple LIKE operator usage in a single query −
mysql> select * from DemoTable1534 -> where ClientName LIKE ('%Doe%' or ClientAge LIKE '%38%') or (ClientCountryName LIKE '%S');
This will produce the following output −
+----------+-------------+-----------+-------------------+ | ClientId | ClientName | ClientAge | ClientCountryName | +----------+-------------+-----------+-------------------+ | 1 | Chris Brown | 29 | AUS | | 3 | John Doe | 43 | US | | 4 | Adam Smith | 38 | US | +----------+-------------+-----------+-------------------+ 3 rows in set, 5 warnings (0.00 sec)
- Related Articles
- Implement multiple COUNT() in a single MySQL query
- Implement SELECT LIKE and CHAR_LENGTH() in a single MySQL query
- Use LIKE % to fetch multiple values in a single MySQL query
- Can we implement 'LIKE' and ‘IN’ in a single MySQL query?
- Multiple LIKE Operators with ORDER BY in MySQL?
- Multiple COUNT() for multiple conditions in a single MySQL query?
- Change multiple columns in a single MySQL query?
- Insert multiple rows in a single MySQL query
- MySQL update multiple records in a single query?
- MySQL query to sort multiple columns together in a single query
- How to get multiple rows in a single MySQL query?
- How to obtain multiple rows in a single MySQL query?
- MySQL query to increase item value price for multiple items in a single query?
- Implement MySQL LIMIT and OFFSET in a single query stating its difference
- Insert multiple values in a temporary table with a single MySQL query?

Advertisements