
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 for Text Search Using LIKE and OR
Let us first create a table −
mysql> create table DemoTable ( Subject text ); Query OK, 0 rows affected (0.86 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Introduction to MySQL'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable values('Deep Dive using Java'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('C in Depth'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Introduction to C++'); Query OK, 1 row affected (0.48 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-----------------------+ | Subject | +-----------------------+ | Introduction to MySQL | | Deep Dive using Java | | C in Depth | | Introduction to C++ | +-----------------------+ 4 rows in set (0.00 sec)
Following is the query for text search with LIKE and OR −
mysql> select *from DemoTable where Subject LIKE '%MySQL%' OR Subject LIKE '%using%';
This will produce the following output −
+-----------------------+ | Subject | +-----------------------+ | Introduction to MySQL | | Deep Dive using Java | +-----------------------+ 2 rows in set (0.00 sec)
Advertisements