
- 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
A single MySQL query to search multiple words from different column values
For this, you can use WHERE clause with multiple LIKE. Let us first create a table −
mysql> create table DemoTable1536 -> ( -> Sentence text -> ); Query OK, 0 rows affected (0.51 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1536 values('I like MySQL database.'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1536 values('Java is an Object Oriented Programming Language'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable1536 values('I only like data structure'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1536 values('MongoDB is NoSQL database'); Query OK, 1 row affected (0.46 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1536;
This will produce the following output −
+--------------------------------------------------+ | Sentence | +--------------------------------------------------+ | I like MySQL database. | | Java is an Object Oriented Programming Language | | I only like data structure | | MongoDB is NoSQL database | +--------------------------------------------------+ 4 rows in set (0.00 sec)
Following is the query to search multiple words −
mysql> select * from DemoTable1536 -> where ( Sentence like '%like%') or (Sentence like '%database%') or (Sentence like '%data%');
This will produce the following output −
+----------------------------+ | Sentence | +----------------------------+ | I like MySQL database. | | I only like data structure | | MongoDB is NoSQL database | +----------------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Get multiple count in a single MySQL query for specific column values
- How do I insert multiple values in a column with a single MySQL query?
- Use LIKE % to fetch multiple values in a single MySQL query
- How to set all values in a single column MySQL Query?
- Inserting multiple parameter values into a single column with MySQL?
- Fastest way to insert with multiple values in a single MySQL query?
- How to alter column type of multiple columns in a single MySQL query?
- Insert multiple values in a temporary table with a single MySQL query?
- How to use a single MySQL query to count column values ignoring null?
- Retrieve MIN and MAX date in a single MySQL query from a column with date values
- MySQL query to sort multiple columns together in a single query
- MySQL query to delete last two words from every column value
- MySQL query to remove special characters from column values?
- Multiple COUNT() for multiple conditions in a single MySQL query?
- MySQL query to display records from a table filtered using LIKE with multiple words?

Advertisements