
- 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
MySQL query for text search with LIKE and OR to fetch records
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)
- Related Articles
- MySQL query to fetch records with arrangement in the form of numbers and letter like 99S, 50K, etc.?
- MySQL query to find a match and fetch records
- MySQL query to fetch records before currentdate + 2 weeks?
- Find the records with % character in a LIKE query with MySQL
- MySQL query to fetch the latest date from a table with date records
- MySQL query to return multiple row records with AND & OR operator
- MySQL query to fetch records from a range of months?
- Implement MySQL REGEXP to fetch records with . and numbers
- MySQL query to fetch records where decimal is a whole number
- MySQL query to fetch records wherein timestamp is before 15+ days?
- Use LIKE % to fetch multiple values in a single MySQL query
- MySQL query to fetch date with year and month?
- Can I search for particular numbers in a MySQL column with comma separated records using a MySQL query?
- How to use MySQL LIKE query to search a column value with % in it?
- MySQL query for alphabetical search (ABC) with REGEXP?

Advertisements