- 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
Remove trailing numbers surrounded by parenthesis from a MySQL column
For this, use trim() along with substring(). Let us first create a table −
mysql> create table DemoTable ( Name varchar(100) ); Query OK, 0 rows affected (0.80 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('1stJohn'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('1stJohn (7)'); Query OK, 1 row affected (0.65 sec) mysql> insert into DemoTable values('2ndSam'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('2ndSam (4)'); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------------+ | Name | +-------------+ | 1stJohn | | 1stJohn (7) | | 2ndSam | | 2ndSam (4) | +-------------+ 4 rows in set (0.00 sec)
Following is the query to remove trailing numbers surrounded by parenthesis from a MySQL column −
mysql> select trim(substring(Name, 1, (CHAR_LENGTH(Name) - LOCATE('(', REVERSE(Name))))) AS RemovingTrailingNumbers from DemoTable;
This will produce the following output −
+-------------------------+ | RemovingTrailingNumbers | +-------------------------+ | 1stJohn | | 1stJohn | | 2ndSam | | 2ndSam | +-------------------------+ 4 rows in set (0.00 sec)
- Related Articles
- Update a column in MySQL and remove the trailing underscore values
- Remove Trailing Zero in MySQL?
- How to remove leading and trailing whitespace from a MySQL field value?
- Python Pandas – Remove leading and trailing whitespace from more than one column
- MySQL query to remove trailing spaces
- Remove small trailing coefficients from a polynomial in Python
- Remove Trailing Zeros from string in C++
- Python Pandas – Remove numbers from string in a DataFrame column
- How can we remove a column from MySQL table?
- Update existing column data in MySQL and remove the last string from a varchar column with strings and numbers
- MySQL query to remove a value with only numbers in a column
- How to remove leading and trailing whitespace in a MySQL field?
- How can I remove the leading and trailing spaces both at once from a string by using MySQL LTRIM() and RTRIM() functions?
- Java Program to remove leading and trailing whitespace from a string
- Remove small trailing coefficients from Chebyshev polynomial in Python

Advertisements