
- 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
How to fetch fields with multiple values set using MySQL LIKE?
To fetch fields with multiple values, use LIKE with OR in MySQL −
select *from yourTableName where yourColumnName like ‘%AnyStringValue’ or yourColumnName like ‘%AnyStringValue’ or yourColumnName like ‘%AnyStringValue’ ……...N;
You can understand with the help of a table −
mysql> create table LikeDemo −> ( −> Hobby varchar(200) −> ); Query OK, 0 rows affected (1.71 sec)
Insert some records in the table with the help of insert command. The query to insert records in the table is as follows −
mysql> insert into LikeDemo values('Reading Book'); Query OK, 1 row affected (0.13 sec) mysql> insert into LikeDemo values('Playing Cricket Match'); Query OK, 1 row affected (0.16 sec) mysql> insert into LikeDemo values('Playing Hockey Match'); Query OK, 1 row affected (0.27 sec) mysql> insert into LikeDemo values('Reading Novel'); Query OK, 1 row affected (0.14 sec) mysql> insert into LikeDemo values('Swimming'); Query OK, 1 row affected (0.10 sec) Displaying all records with the help of select statement. The query is as follows: mysql> select *from LikeDemo;
The following is the output −
+-----------------------+ | Hobby | +-----------------------+ | Reading Book | | Playing Cricket Match | | Playing Hockey Match | | Reading Novel | | Swimming | +-----------------------+ 5 rows in set (0.00 sec)
The query to fetch fields with multiple values using LIKE is as follows −
mysql> select *from LikeDemo where Hobby like '%Cricket%' or Hobby like '%Reading%';
The following is the output −
+-----------------------+ | Hobby | +-----------------------+ | Reading Book | | Playing Cricket Match | | Reading Novel | +-----------------------+ 3 rows in set (0.00 sec)
- Related Articles
- How to use MySQL LIKE clause to fetch multiple values beginning with “Joh”
- Use LIKE % to fetch multiple values in a single MySQL query
- MySQL query to fetch multiple least values?
- MySQL query to find same value on multiple fields with LIKE operator?
- Can we fetch multiple values with MySQL WHERE Clause?
- SHOW TABLE statement with multiple LIKE values in MySQL?
- How to fetch random rows in MySQL with comma separated values?
- Search multiple fields for multiple values in MongoDB?
- Set multiple values for custom columns in MySQL?
- MySQL query for text search with LIKE and OR to fetch records
- MySQL query to display records from a table filtered using LIKE with multiple words?
- Multiple LIKE Operators with ORDER BY in MySQL?
- How to delete fields with values more than a particular value in MySQL?
- Fetch records from comma separated values using MySQL IN()?
- Fetch maximum value from multiple columns with null and non-null values?

Advertisements