

- 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
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 Questions & Answers
- 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?
- 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 regular expression to update a table with column values including string, numbers and special characters
- MySQL query to keep only first 2 characters in column value and delete rest of the characters?
- MySQL query to compare and display only the rows with NULL values
- MySQL query to return the count of only NO values from corresponding column value
- Fetch a specific record from a column with string values (string, numbers and special characters) in MySQL
- Retrieve MIN and MAX date in a single MySQL query from a column with date values
- MySQL query to replace only the NULL values from the table?
Advertisements