
- 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
MySQL query to retrieve only the column values with special characters?
For this, use REGEXP. Let us first create a table −
mysql> create table DemoTable(SubjectCode varchar(100)); Query OK, 0 rows affected (0.89 sec)
Insert some records in the table using insert command. The records consists of text, numbers and special characters −
mysql> insert into DemoTable values('Java899@22'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('C#'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('~Python232'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('MongoDB%'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('C123456'); Query OK, 1 row affected (0.37 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------------+ | SubjectCode | +-------------+ | Java899@22 | | C# | | ~Python232 | | MongoDB% | | C123456 | +-------------+ 5 rows in set (0.00 sec)
Following is the query to get all the values with special characters −
mysql> select *from DemoTable where SubjectCode regexp '[^a-zA-Z0-9\&]';
This will produce the following output −
+-------------+ | SubjectCode | +-------------+ | Java899@22 | | C# | | ~Python232 | | MongoDB% | +-------------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL query to remove special characters from column values?
- Append special characters to column values in MySQL
- MySQL query to replace special characters from column value
- MySQL query to display only the column values with corresponding column having whitespace
- MySQL query to select a specific string with special characters
- How to use special characters in column names with MySQL?
- MySQL regular expression to update a table with column values including string, numbers and special characters
- Return only the first 15 characters from a column with string values in MySQL
- MySQL query to find the average of only first three values from a column with five values
- MySQL query to keep only first 2 characters in column value and delete rest of the characters?
- Retrieve MIN and MAX date in a single MySQL query from a column with date values
- Fetch a specific record from a column with string values (string, numbers and special characters) in MySQL
- MySQL query to return the count of only NO values from corresponding column value
- MySQL query to compare and display only the rows with NULL values
- MySQL query to split a column after specific characters?

Advertisements