- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 to match any of the two strings from column values
For this, you can use LIKE operator with OR condition.
Let us first create a table −
mysql> create table DemoTable762 (Title text); Query OK, 0 rows affected (0.54 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable762 values('Introduction to Java'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable762 values('MySQL is a RDBMS'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable762 values('Data Structure and Algorithm in Java'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable762 values('Data Structure and Algorithm in C and C++'); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable762 ;
This will produce the following output -
+-------------------------------------------+ | Title | +-------------------------------------------+ | Introduction to Java | | MySQL is a RDBMS | | Data Structure and Algorithm in Java | | Data Structure and Algorithm in C and C++ | +-------------------------------------------+ 4 rows in set (0.00 sec)
Following is the query to match any of the two strings “MySQL” or “Algorithm” −
mysql> select *from DemoTable762 where Title LIKE '%MySQL%' or Title LIKE '%Algorithm%';
This will produce the following output -
+-------------------------------------------+ | Title | +-------------------------------------------+ | MySQL is a RDBMS | | Data Structure and Algorithm in Java | | Data Structure and Algorithm in C and C++ | +-------------------------------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Match column values on the basis of the other two column values in MySQL
- MySQL query to get first two highest column values from a table?
- MySQL query to remove special characters from column values?
- MySQL query to display the first alphabet from strings in a separate column
- MySQL query to count all the column values from two columns and exclude NULL values in the total count?
- MySQL query to increment one of the column values
- MySQL query to fetch the maximum corresponding value from duplicate column values
- MySQL query to return the count of only NO values from corresponding column value
- MySQL ENUM column match for quoted values
- MySQL query to find the average of only first three values from a column with five values
- A single MySQL query to search multiple words from different column values
- MySQL query to delete last two words from every column value
- How do I select data from one table only where column values from that table match the column values of another table in MySQL?
- How can we match the values having backslashes, like ‘ab’, from MySQL column?
- MySQL query to calculate the total amount from column values with Cost and Quantity?

Advertisements