
- 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
Search for specific characters within a string with MySQL?
For this, use REGEXP. For example, characters J, A, V and A. Let us first create a table −
mysql> create table DemoTable ( Value varchar(50) ); Query OK, 0 rows affected (3.92 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('XYSJGHAKLMVDFFSA'); Query OK, 1 row affected (0.67 sec) mysql> insert into DemoTable values('PQRSTJAVAL'); Query OK, 1 row affected (0.58 sec) mysql> insert into DemoTable values('SJATUVAK'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('JSTUVA'); Query OK, 1 row affected (0.32 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------------------+ | Value | +------------------+ | XYSJGHAKLMVDFFSA | | PQRSTJAVAL | | SJATUVAK | | JSTUVA | +------------------+ 4 rows in set (0.00 sec)
Following is the query to search for characters within a string with MySQL −
mysql> select *from DemoTable where Value REGEXP '.*J.*A.*V.*A';
This will produce the following output −
+------------------+ | Value | +------------------+ | XYSJGHAKLMVDFFSA | | PQRSTJAVAL | | SJATUVAK | +------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Search for a string within text column in MySQL?
- How to search a MySQL table for a specific string?
- MySQL query to select a specific string with special characters
- Set characters at a specific position within the string in Arduino
- MySQL query to search within the last 5 characters in a column?
- Search a string with special characters in a MongoDB document?
- Fetch a specific record from a column with string values (string, numbers and special characters) in MySQL
- Query in MySQL for string fields with a specific length?
- How to scan a string for specific characters in Python?
- Python - Search DataFrame for a specific value with pandas
- Quickly search for a string in MySQL database?
- Search Within Specific File Types Using grep on Linux
- MySQL search if more than one string contains special characters?\n
- How to search specific word in MySQL with RegExp?
- Find if a string begins with a specific set of characters in Arduino

Advertisements