
- 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 perform string matching in MySQL?
For string matching, use LIKE operator. Let us first create a table −
mysql> create table DemoTable -> ( -> MonthName varchar(100) -> ); Query OK, 0 rows affected (0.63 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('JFMA'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('JMA'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('JDN'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('JFOSA'); Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+-----------+ | MonthName | +-----------+ | JFMA | | JMA | | JDN | | JFOSA | +-----------+ 4 rows in set (0.00 sec)
Following is the query to perform string matching in MySQL −
mysql> select *from DemoTable WHERE MonthName LIKE '%J%M%';
Output
+-----------+ | MonthName | +-----------+ | JFMA | | JMA | +-----------+ 2 rows in set (0.00 sec)
- Related Articles
- C++ Program to Perform String Matching Using String Library
- How to perform Multiline matching with JavaScript RegExp?
- How to perform Case Insensitive matching with JavaScript RegExp?
- How MySQL can perform case-sensitive string comparison?
- How to perform string comparison in TypeScript?
- How to perform Increment in MySQL Update?
- How to perform string aggregation/concatenation in Oracle?
- How to perform SELECT using COUNT in MySQL?
- How to perform conditional GROUP BY in MySQL to fetch?
- MySQL query not matching due to punctuation?
- Wildcard matching of string JavaScript
- How to perform custom sort by field value in MySQL?
- Program to perform string compression in Python
- C++ Program to Implement String Matching Using Vectors
- C++ Program to Implement Bitap Algorithm for String Matching

Advertisements