

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
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 Questions & Answers
- 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 find same value on multiple fields with LIKE operator?
- MySQL query to fetch multiple least values?
- SHOW TABLE statement with multiple LIKE values in MySQL?
- Can we fetch multiple values with MySQL WHERE Clause?
- Search multiple fields for multiple values in MongoDB?
- Multiple LIKE Operators with ORDER BY in MySQL?
- MySQL query for text search with LIKE and OR to fetch records
- How to fetch random rows in MySQL with comma separated values?
- MySQL query to display records from a table filtered using LIKE with multiple words?
- Set multiple values for custom columns in MySQL?
- Fetch records from comma separated values using MySQL IN()?
- How to delete fields with values more than a particular value in MySQL?
- Fetch maximum value from multiple columns with null and non-null values?
Advertisements