
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
Using LIKE Clause Twice in a MySQL Query
Let us first create a table −
mysql> create table DemoTable2009 ( Name varchar(20) ); Query OK, 0 rows affected (0.51 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable2009 values('John Doe'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2009 values('Adam Smith'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable2009 values('John Smith'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2009 values('David Miller'); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable2009;
This will produce the following output −
+--------------+ | Name | +--------------+ | John Doe | | Adam Smith | | John Smith | | David Miller | +--------------+ 4 rows in set (0.00 sec)
Here is the query to use LIKE clause twice in a MySQL query −
mysql> select * from DemoTable2009 where Name like '%Smith%' or Name like '%David%';
This will produce the following output −
+--------------+ | Name | +--------------+ | Adam Smith | | John Smith | | David Miller | +--------------+ 3 rows in set (0.00 sec)
Advertisements